简体   繁体   中英

Integrate phpgrid with codeigniter

Im trying to integrate phpgrid with my codeigniter program.

I need a few clarifications on how to use the library function.

I have added the phpgrid files to the application/libraries path and I have loaded the libray using $this->load->library('phpGrid');

Below is the code in the phpgrid conf.php file.

<?php
// mysql example
define('DB_HOSTNAME','localhost'); // database host name
define('DB_USERNAME', 'admin');     // database user name
define('DB_PASSWORD', 'pop3'); // database password
define('DB_NAME', xtra); // database name     
define('DB_TYPE', 'mysql');  // database type
define('DB_CHARSET','utf8'); // ex: utf8(for mysql),AL32UTF8 (for oracle), leave blank to use the default charset


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

/******** DO NOT MODIFY ***********/
require_once('phpGrid.php');     
/**********************************/
?>

Can someone please help me how can I reference the define and require_once files to my library path?

Or is there any other way that I can include the phpgrid files to my CI project?

I've just looked at the PHPgrid source files and it appears that they are encrypted so you are limited as to how much you can fully "integrate" with Codeigniters MVC framework.

To work with an external library like this, here's what I would generally do:

Store a separate config.php file (that looks like the PHPgrid one) that defines the db connection constants in the root directory.

Then require this in your Codeigniter config/database.php file and use the constants to set the Codeigniter settings as well. So your Codeigniter database.php would look like:

require_once('config.php');

$db['default']['hostname'] = DB_HOSTNAME;

$db['default']['username'] = DB_USERNAME;

$db['default']['password'] = DB_PASSWORD;

$db['default']['database'] = DB_NAME;

You don't want to be storing database connection details all over the place.

Then include config.php at the top of your phpgrid/conf.php file, and use the constants to fill the details the same way, obviously fill out the other phpgrid constants as well.

Put all the PHPgrid files in a subdir of application/libraries. Now create a new file in your application/libraries file that is called something like ci_phpgrid.php and in it create a new class like below:

<?php
require_once('phpgrid/conf.php');

class CI_phpgrid {

    public function example_method($val = '')
    {
        $dg = new C_DataGrid("SELECT * FROM Orders", $val, "Orders");
        return $dg;
    }
}

You can now use this to communicate with php grid, leaving the original files intact.

In you controller you would just do something like:

$this->load->library('ci_phpgrid');
$data['phpgrid'] = $this->ci_phpgrid->example_method(3)

$this->load->view('home_page',$data);

And then in the view you can display the table using:

$phpgrid->display()

As I mentioned, I've not used PHPgrid and you'll need to include all the relevant JS for sorting etc but this is generally the way you want to approach external libraries in CI.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM