Integrate phpgrid with codeigniter

前端 未结 1 899
轻奢々
轻奢々 2020-12-21 14:46

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 t

相关标签:
1条回答
  • 2020-12-21 15:06

    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.

    0 讨论(0)
提交回复
热议问题