Click here to Skip to main content
15,881,600 members
Articles / All Topics

phpGrid and Codeigniter Integration

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
9 Jul 2015CPOL2 min read 12.5K   1
phpGrid and Codeigniter Integration

phpGrid-Codeigniter-outcome

Introduction

It’s easy to integrate CodeIgniter with phpGrid. CodeIgniter is a popular, open source PHP framework loosely based on MVC development pattern for use in building dynamic web sites. Out of the box, phpGrid is a read-to-use PHP datagrid solution.

Install CodeIgniter

Download CodeIgniter here. CodeIgniter is installed in four steps:

  1. Unzip the package.
  2. Upload the CodeIgniter folders and files to your server. Normally the index.php file will be at your root.
  3. Open the application/config/config.php file with a text editor and set your base URL. If you intend to use encryption or sessions, set your encryption key.
  4. If you intend to use a database, open the application/config/database.php file with a text editor and set your database settings.

Install phpGrid

Download phpGrid here. Install phpGrid in the followings steps:

  1. Unzip the phpGrid download file.
  2. Upload unzipped phpGrid folder to “aplication/libraries” folder.
  3. Complete the installation by configuring the conf.php file. For instructions on how to do this, see setup phpGrid configuration.

CodeIgniter Controller

For the sake of this tutorial, we will directly modify the default controller file “Welcome.php”. In practice, it can be any existing or new controller file. Pay attention that we did not initialize the class using the standard:

PHP
  1  $this->load->library('someclass');

Where someclass is the file name, without the “.php” file extension. Instead, we simply include phpGrid configuration file. APPPATH constant is path to your application folder. Unlike Laravel framework, you can directly include PHP classes and working with them. phpGrid is a complex component and composed of multiple classes.

C#
  1  public function index()
  2  {
  3      // $this->load->view('welcome_message');
  4  
  5      require_once(APPPATH. 'libraries/phpGrid_Lite/conf.php'); // APPPATH is path to application folder
  6      $data['phpgrid'] = new C_DataGrid("SELECT * FROM Orders", 
  7      "orderNumber", "Orders"); //$this->ci_phpgrid->example_method(3);
  8  
  9      $this->load->view('show_grid',$data);
 10  }

Note the last line is our new view we are about to create. The view is called “show_grid”.

phpGrid-Codeigniter-code

Create View

Our view is very simple in this tutorial. All you have to do is to put <?php $phpgrid->display(); ?> somewhere in the view. Learn more about creating a basic PHP grid here.

PHP
  1  <?php
  2  defined('BASEPATH') OR exit('No direct script access allowed');
  3  ?><!DOCTYPE html>
  4  <html lang="en">
  5  <head>
  6      <meta charset="utf-8">
  7      <title>Show Grid</title>
  8  </head>
  9  <body>
 10  
 11  <div id="container">
 12      <h1>Welcome to CodeIgniter! Show me the grid!</h1>
 13  
 14      <div id="body">
 15          <?php $phpgrid->display(); ?>
 16      </div>
 17  
 18  </div>
 19  
 20  </body>
 21  </html>

That’s it! phpGrid handles all the CRUD operations. We don’t need to create Model for PHP datagrid to run in CodeIgniter.

The post phpGrid and Codeigniter Integration appeared first on phpGrid.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United States United States
He likes programming and iPod.

Comments and Discussions

 
QuestionHow to integrate it in phpgrid .org? Pin
Member 136109517-Jan-18 6:47
Member 136109517-Jan-18 6:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.