Codeigniter中的自动加载库

raa*_*van 0 codeigniter autoload

我是Codeigniter的新手.我在自动加载中有3个库config.php.

但在我的一个控制器中,我不想加载库.这可能吗?

Muh*_*eel 6

如果您需要整个应用程序中的任何库,您可以将其加载到配置文件中,它将自动加载.但是,如果您只需要特定控制器中的库,则可以将其加载到您需要的控制器中.

Class test Extends CI_Controller{

    function index()
    {
        $this->load->library('mylibrary');
        $this->mylibrary->somemethod();    
    }

}
Run Code Online (Sandbox Code Playgroud)

或者如果您需要通过控制器的库,您可以在构造函数中加载它.

Class test Extends CI_Controller{

    function __construct()
    {
       parent::__construct();
         $this->load->library('mylibrary');
    }

    function index(){
         $this->mylibrary->somemethod();    
    }
    function test(){
         $this->mylibrary->someothermethod();    
    }

}
Run Code Online (Sandbox Code Playgroud)