This is a step-by-step tutorial of how to integrate the Laravel PHP framework with phpGrid.
Laravel is a free, open-source PHP web application framework architected in a model–view–controller (MVC) pattern. phpGrid is a standalone CRUD component which includes all the necessary server and client side scripts. It does not need the Laravel packaging system to manage dependency.
System Requirements:
- Laravel 7
- PHP >= 7.2 (required by Laravel)
- MCrypt PHP Extension or OpenSSL (required by Laravel)
- phpGrid Lite (free)
- Relational Database, e.g. MySQL
Laravel requires PHP version 7.2+ and MCrypt PHP Extension. Check your phpinfo file to verify the PHP. In this tutorial, we will be using the free version of phpGrid, phpGrid Lite.
Setting up Laravel:
The easiest way is to install Laravel is by using Composer. However, the Laravel installation procedure is outside the scope of this tutorial. Please visit http://laravel.com/docs/ for the Laravel installation process. For this demo, we will install the Laravel folder in the web server’s root directory.
phpGrid Folder Location in Laravel:
It is a common practice to save third-party libraries to Laravel “app/libraries” folder. However, the correct path to put phpGrid is in the Laravel “public” folder. This is because phpGrid is more than just the back-end of the PHP classes. It also contains front-end user accessible stylesheets and Javascript to render the datagrid. Such a library must reside in Laravel “public” directory because it is the public directory is the root directory that is accessible to users when they visit your website.
conf.php
Now we need to setup the database connection and script path information in the file “conf.php”. Since phpGrid resides in “public” folder – Laravel’s front-end root directory – the value of phpGrid SERVER_ROOT should be “/phpGrid_Lite”. Don’t forget the slash at the beginning.
Learn more about SERVER_ROOT and other of phpGrid system variables here.
1 |
Laravel views:
Finally, we need to create a view file in the Laravel “app/views” folder. Since phpGrid is located in Laravel’s “public” folder, we can reference the path to its conf.php file with Laravel’s public_path() helper function.
1 2 3 4 5 6 | use phpCtrl\C_DataGrid; require_once(public_path() ."/phpGrid_Lite/conf.php"); $dg = new C_DataGrid("SELECT * FROM orders", "orderNumber", "orders"); $dg->enable_edit("INLINE", "CRUD"); $dg->display(); |
Note that “orders” is a database table from the phpGrid sample database…. And that’s all there is to it! You have now integrated the power of phpGrid with the Laravel platform.