将phpgrid与codeigniter集成 [英] Integrate phpgrid with codeigniter

查看:104
本文介绍了将phpgrid与codeigniter集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将 phpgrid 与我的codeigniter程序集成。



我需要一些澄清如何使用库函数。



我已经添加了phpgrid文件到应用程序/库路径,我已经加载的库使用 $ this-> load-> library('phpGrid');



下面是phpgrid conf .php文件。

 <?php 
// mysql示例
define('DB_HOSTNAME' 'localhost'); //数据库主机名
define('DB_USERNAME','admin'); //数据库用户名
define('DB_PASSWORD','pop3'); //数据库密码
define('DB_NAME',xtra); // database name
define('DB_TYPE','mysql'); //数据库类型
define('DB_CHARSET','utf8'); // ex:utf8(for mysql),AL32UTF8(for oracle),留空以使用默认字符集


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

/ ********不要修改*********** /
require_once('phpGrid.php');
/ ********************************** /
?>

有人可以帮助我如何引用define和require_once文件到我的库路径? p>

或者还有其他方法可以将phpgrid文件包含到我的CI项目中。

解决方案

我刚刚看了PHPgrid源文件,它似乎是加密的,所以你有限的,你可以完全集成Codeigniters MVC框架。



要使用这样的外部库,下面是我通常会做的:





然后在你的Codeigniter config / database.php文件中要求这个文件,使用常量来设置Codeigniter设置。所以你的Codeigniter database.php看起来像:

  require_once('config.php'); 

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

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

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

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

您不想在整个地方存储数据库连接详细信息。



然后在你的phpgrid / conf.php文件的顶部包含config.php,并使用常量以相同的方式填充细节,显然填写其他phpgrid



将所有PHPgrid文件放在应用程序/库的子目录中。现在在你的应用程序/库文件中创建一个名为ci_phpgrid.php的新文件,并在其中创建一个新类,如下所示:

 <?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;
}
}

现在可以使用它与php grid通信,



在您的控制器中,您只需执行以下操作:

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

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

然后在视图中,您可以使用以下命令显示表:

  $ phpgrid-> display()

正如我所提到的,我没有使用PHPgrid,你需要包括所有相关的JS用于排序等,但这通常是你想要在CI中处理外部库的方式。


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.

这篇关于将phpgrid与codeigniter集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆