65.9K
CodeProject is changing. Read more.
Home

phpGrid Laravel Integration

starIconstarIconstarIconstarIconemptyStarIcon

4.00/5 (1 vote)

Jul 2, 2015

CPOL

2 min read

viewsIcon

8190

phpGrid Laravel integration

This is a step-by-step tutorial of how to integrate Laravel PHP framework with phpGrid.

Laravel is a free, open-source PHP web application framework, architected in model–view–controller (MVC) pattern. phpGrid is a standalone CRUD component encapsulating all the necessary server and client side scripts and does not require Laravel packaging system for managing dependency.

System Requirements

  • Laravel 4
  • PHP >= 5.4 (required by Laravel)
  • MCrypt PHP Extension (also required by Laravel)
  • phpGrid Lite (free)
  • Relational Database, e.g. MySQL

Laravel requires PHP version 5.4+ and MCrypt PHP Extension. Check your phpinfo to verify PHP version and MCrypt. In tutorial, we will be using free phpGrid Lite version.

php mcrypt

Set Up Laravel

The easiest way is to install Laravel is to use Composer. However, installation procedure is outside the scope of this tutorial. Please visit http://laravel.com/docs/ for Laravel installation process. For the demo, we install Laravel folder in web server root directory.

phpGrid Folder Location in Laravel

It’s common to save third-party libraries to Laravel “app/libraries”. However, the correct place to put phpGrid is actually in Laravel “public” folder. This is because phpGrid is more than just the eback-end PHP classes but also contains front-end user accessible stylesheets and JavaScript to render datagrid. Such library must reside in the application’s “public” directory because Laravel public directory is the root directory that is accessible to users when they visit your website.

phpgrid-laravel-folder

phpGrid conf.php

You would need to setup the database connection and script path information in file “conf.php”. Since phpGrid resides in “public” folder, Laravel’s front-end root directory, phpGrid SERVER_ROOT value should be “/phpGrid_Lite”. Pay attention to the beginning slash character.

Learn more about SERVER_ROOT and rest of phpGrid system variables here.

define('SERVER_ROOT', '/phpGrid_Lite');

Laravel Views

Finally, one must create a view file in Laravel “app/views” folder. Since phpGrid is located in Laravel “public” folder, we can reference path to conf.php with Laravel’s public_path() helper function.

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 phpGrid sample database.

phpgrid-laravel-demo

The post phpGrid Laravel Integration appeared first on phpGrid.