문제

I've ran into a problem that can't seem to have an answer.

I am using CodeIgniter 2.1.4 with HMVC.

My question is: How can I load a core library in a controller of a module?

I want to load the "database" library (which is a core library) inside a method of a controller (or model for that matter) in order to avoid connecting to the database if there is no need to do it (when i have cached results inside a text file).

I understand that you can use autoload per module, but I only want to load the library if some conditions are met.

I also know you can load libraries that are inside the libraries folder of the module folder, but if I only need one database why would I paste the database library inside every single module just to make the connection.

When I try to load the library with "$this->load->library('database');", it gives me the following error:"Unable to load the requested class: database". Could you please help?

도움이 되었습니까?

해결책

You can load a database with:

$this -> load -> database();

Whenever you want to load a specific database, you give the name of the database to the load function:

$this -> load -> database('DBname');

Where you specify your database propeties in config\database.php. Note that you define your database name/group with the first key:

$db['This is your database group']['hostname'] = '127.0.0.1';

see here.


Hope this was helpful.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top