Get KoolPHP UI with 30% OFF!

loading koolgrid libraries into Laravel

Shaun
Hi Guys
Can anyone help me with getting koolgrid/koolphp working in Laravel ?
I've noticed that if Im loading the koolajax, koolgrid and advancedarraydatasource the only call that autoloads into the global namespace is the advancedarraydatasource.
Thanks
Shaun
Posted Sep 14, 2015 , edited Sep 14, 2015 Kool -
Shaun
OK, got over that hurdle, but I cant load the koolgrid classes in the recommended manner documented with laravel.
This however does work.
$koolgridpath = base_path() . '/public/koolcontrols';
require $koolgridpath . '\KoolGrid\koolgrid.php';
require $koolgridpath . '\KoolGrid\ext\datasources\AdvancedArrayDataSource.php';
require $koolgridpath . '\KoolAjax\koolajax.php';
require $koolgridpath . '\KoolAutoComplete\koolautocomplete.php';
Posted Sep 15, 2015 Kool
Shaun
The issue I have now is that it seems like I'm not referencing the scriptfolder for koolgrid correctly.
$grid->scriptFolder =  $koolgridpath . '/KoolGrid/';

Here is my current result.
Posted Sep 15, 2015 , edited Sep 15, 2015 Kool
Peter
Please set the scriptFolder absolute path like this:
$grid->scriptFolder = "/control/public/koolcontrols/KoolGrid";
Posted Sep 15, 2015 Kool
Shaun
Thanks Pete
I got it right with
$grid->scriptFolder =  "http://control.dev/koolcontrols/KoolGrid/";

Then after looking at your post :
$grid->scriptFolder =  /koolcontrols/KoolGrid/";
"
this works great ;)
Just 1 more issue , but let me play a bit first ;)
Posted Sep 15, 2015 Kool
Shaun
ok, everything loads now but ..... drum roll.
I cant page through the records.
You can click on next to go to the next page. The ajax loader animation plays but you remain on the same page.
l
Posted Sep 15, 2015 Kool
Shaun
ok, looking at the Laravel logs it seems like Lavarel has something to do with this issue ;) ( The pains of learning a framework ;) )
[2015-09-15 12:14:25] local.ERROR: exception 'Illuminate\Session\TokenMismatchException' in E:\laragon\www\control\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\VerifyCsrfToken.php:53
Stack trace:
#0 [internal function]: Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle(Object(Illuminate\Http\Request), Object(Closure))
#1 E:\laragon\www\control\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(124): call_user_func_array(Array, Array)
#2 E:\laragon\www\control\vendor\laravel\framework\src\Illuminate\View\Middleware\ShareErrorsFromSession.php(54): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#3 [internal function]: Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#4 E:\laragon\www\control\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(124): call_user_func_array(Array, Array)
#5 E:\laragon\www\control\vendor\laravel\framework\src\Illuminate\Session\Middleware\StartSession.php(62): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#6 [internal function]: Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#7 E:\laragon\www\control\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(124): call_user_func_array(Array, Array)
#8 E:\laragon\www\control\vendor\laravel\framework\src\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse.php(37): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#9 [internal function]: Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure))
#10 E:\laragon\www\control\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(124): call_user_func_array(Array, Array)
#11 E:\laragon\www\control\vendor\laravel\framework\src\Illuminate\Cookie\Middleware\EncryptCookies.php(59): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#12 [internal function]: Illuminate\Cookie\Middleware\EncryptCookies->handle(Object(Illuminate\Http\Request), Object(Closure))
#13 E:\laragon\www\control\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(124): call_user_func_array(Array, Array)
#14 E:\laragon\www\control\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode.php(42): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#15 [internal function]: Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure))
#16 E:\laragon\www\control\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(124): call_user_func_array(Array, Array)
#17 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#18 E:\laragon\www\control\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(103): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#19 E:\laragon\www\control\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(122): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#20 E:\laragon\www\control\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(87): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))
#21 E:\laragon\www\control\public\index.php(54): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#22 {main}
Posted Sep 15, 2015 , edited Sep 15, 2015 Kool
Shaun
So it seems to be a token mismatch exception brought on by the AJAX post.
In the Laravel documentation I can either Excluding URIs From CSRF Protection (which I would rather not do) or
as documented :
In addition to checking for the CSRF token as a POST parameter, the Laravel VerifyCsrfToken middleware will also check for the X-CSRF-TOKEN request header. You could, for example, store the token in a "meta" tag:

<meta name="csrf-token" content="{{ csrf_token() }}">

Once you have created the meta tag, you can instruct a library like jQuery to add the token to all request headers. This provides simple, convenient CSRF protection for your AJAX based applications:

$.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
}); 

I'm just not sure how to implement the above. I'll test the Excluding URIs From CSRF Protection for now.
Posted Sep 15, 2015 Kool
Shaun
ok, by adding the uri in my case being (portal/cdrbrowser), which where the koolgrid is residing to VerifyCsrfToken middleware
the grid and koolajax works like a boss.

protected $except = [
        //  'awesome/*',
          'portal/cdrbrowser',
    ];

But i would really prefer to use the X-CSRF-TOKEN method mentioned in the above post.
Posted Sep 15, 2015 Kool
Peter
That's great that you made it work. I have recorded this issue as a suggestion to improve grid and ajax to work with the csrf token.
Posted Sep 15, 2015 Kool
Shaun
cool :)
Posted Sep 15, 2015 Kool