[英]Loading multiple libraries in codeigniter using array(). First library works, but second doesn't
I'm loading two controllers from within my main controller and only the first one loads. 我要从主控制器中加载两个控制器,而只有第一个加载。
class App extends CI_Controller {
public function index() {
$this->load->library(array('../controllers/effects',
'../controllers/ingredients'));
$data['ingredients'] = $this->ingredients->get_all();
$data['effects'] = $this->effects->get_all();
$this->load->view('header');
$this->load->view('main', $data);
$this->load->view('footer');
}
}
I'm getting the error Message: Undefined property: App::$ingredients
. 我收到错误Message: Undefined property: App::$ingredients
。 If I switch the two path strings like this 如果我这样切换两个路径字符串
$this->load->library(array('../controllers/ingredients', '../controllers/effects'));
then it says effects is undefined so it looks like it always loads the first controller but not the second. 然后说效果是不确定的,因此看起来总是加载第一个控制器,而不是第二个。 I tried autoloading them as well but I got an error like "nested function limit exceeded" or something. 我也尝试自动加载它们,但是出现类似“超出嵌套功能限制”之类的错误。 What am I doing wrong, how can I fix this? 我做错了什么,该如何解决?
put your library file in libraries
folder inside CI
把你的库文件中libraries
文件夹里面CI
Now you can load your library in controller 现在您可以将库加载到控制器中
$this->load->library('library_name');
to load multiple libraries in array 加载数组中的多个库
$this->load->library(array('library_name_1', 'library_name_2'));
or you can Auto-load Libraries in config/autoload.php 或者您可以在config / autoload.php中自动加载库
$autoload['libraries'] = array('library_name_1', 'library_name_2');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.