Php 在钩子中扩展Codeigniter配置

Php 在钩子中扩展Codeigniter配置,php,codeigniter,Php,Codeigniter,我需要设置数据库中定义的其他配置。我的想法是在pre_控制器钩子中扩展CI配置 钩子不是问题,但是如何以正确的方式扩展CI配置 如果可能的话,有人能给我举个例子解释一下吗 除此之外,如果我将其挂接到pre_controller中,它是否会在每个请求上使用缓存检查数据库中的配置和值,因为我需要在每个请求上检查表?不必使用钩子 在application/core/create中创建基本应用程序控制器ex:AppController class AppController extends CI_Con

我需要设置数据库中定义的其他配置。我的想法是在pre_控制器钩子中扩展CI配置

钩子不是问题,但是如何以正确的方式扩展CI配置

如果可能的话,有人能给我举个例子解释一下吗


除此之外,如果我将其挂接到pre_controller中,它是否会在每个请求上使用缓存检查数据库中的配置和值,因为我需要在每个请求上检查表?

不必使用钩子

在application/core/create中创建基本应用程序控制器ex:AppController

class AppController extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();

        $config = $this->db->get('config')->result();

        foreach ($config as $config_item)
        {
            $this->config->set_item($config_item->name, $config_item->value);
        }
    }

}
class Main extends AppController
{
    // other functions
}
并且所有应用程序控制器都从AppController扩展

class AppController extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();

        $config = $this->db->get('config')->result();

        foreach ($config as $config_item)
        {
            $this->config->set_item($config_item->name, $config_item->value);
        }
    }

}
class Main extends AppController
{
    // other functions
}

不一定要用钩子

在application/core/create中创建基本应用程序控制器ex:AppController

class AppController extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();

        $config = $this->db->get('config')->result();

        foreach ($config as $config_item)
        {
            $this->config->set_item($config_item->name, $config_item->value);
        }
    }

}
class Main extends AppController
{
    // other functions
}
并且所有应用程序控制器都从AppController扩展

class AppController extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();

        $config = $this->db->get('config')->result();

        foreach ($config as $config_item)
        {
            $this->config->set_item($config_item->name, $config_item->value);
        }
    }

}
class Main extends AppController
{
    // other functions
}

谢谢你的回答,用其他方式做不是更好吗?通过这种方式,我有两个扩展…除此之外,我还有很多控制器要更改,因为它们都扩展了CI_控制器…在钩子中添加pre_系统钩子,在钩子文件中可以$CI=&get_instance();和$CI->load->database()$CI->database->get();$CI->load->{config_class}和$CI->config->set_item();这就是例子!!!谢谢你的回答,用其他方式做不是更好吗?通过这种方式,我有两个扩展…除此之外,我还有很多控制器要更改,因为它们都扩展了CI_控制器…在钩子中添加pre_系统钩子,在钩子文件中可以$CI=&get_instance();和$CI->load->database()$CI->database->get();$CI->load->{config_class}和$CI->config->set_item();这就是例子!!!