这可能会有所帮助.. 模型可能是您最好的选择。下面我给出了一些关于如何使用controlelrs/models/libraries的insite,我会将我的mysql代码放入适当的模型文件中。并通过任何控制器调用它
// 库/profiles.php
class My_library
{
protected $CI;
public function __construct()
{
$this->CI =& get_instance(); // Existing Code Igniter Instance
}
public function my_lib_method()
{
// Your Code Here
// can communicate back with CI by using $this->CI
// $this->CI->load->view(....);
// $this->CI->load->model(...);
// ETC
}
}
// 模型/my_model.php
class My_model extends CI_Model{
public function my_mdl_method(){
// Your Code Here
}
}
// 控制器/my_controller.php
class My_controller extends CI_Controller
{
public function my_ctrl_method(){
$this->load->library('my_library');
$this->load->model('my_model');
// calling a library method
$this->my_library->my_lib_method();
// calling a model method
$this->my_model->my_mdl_method();
}
}