[英]Loading more than one libraries in CodeIgniter - PHP
I need to load more than 2 libraries in a CI Controller and call their member functions. 我需要在CI控制器中加载2个以上的库并调用它们的成员函数。 I've tried the following ways but no use.
我尝试了以下方法,但没有用。
1. 1。
$this->load->library('liba');
$result = $this->liba->SearchTours($searchParams);
echo $result;
$this->load->library('libb');
$result2 = $this->libb->tourFetch($searchParams);
echo $result2;
2. 2。
$this->load->library(array('liba' , 'libb'));
$result = $this->liba->SearchTours($searchParams);
echo $result;
$result2 = $this->libb->tourFetch($searchParams);
echo $result2;
3. 3。
$this->load->library('liba');
$this->load->library('libb');
$result = $this->liba->SearchTours($searchParams);
echo $result;
$result2 = $this->libb->tourFetch($searchParams);
echo $result2;
4. 4。
public function __construct(){
parent::__construct();
$this->load->library('liba');
$this->load->library('libb');
}
In all the cases only the first mentioned library is loaded and this Notice shows for the second one. 在所有情况下,只加载第一个提到的库,本通知显示第二个。
A PHP Error was encountered Severity: Notice Message: Undefined property: Unify::$libb Filename: controllers/Unify.php Line Number: 30
I couldn't find any soultion on CI user manual or SO. 我在CI用户手册或SO上找不到任何灵魂。 What am I doing wrong?
我究竟做错了什么?
load multiple library in CI Just pass in it array 在CI中加载多个库只需传入它的数组
$this->load->library( array('liba', 'libb') );
and this notice because you not include 和这个通知,因为你没有包括
$CI =& get_instance();
inside your controller 在你的控制器内
Is the file in your controllers folder. 该文件是您的controllers文件夹中的文件。 If yes then You might not have properly extended your controller.
如果是,那么您可能没有正确扩展您的控制器。 Like:
喜欢:
myController extends CI_Controller{}
else You need to use $CI =& get_instance();
否则你需要使用
$CI =& get_instance();
inside your file and then use 在你的文件中,然后使用
$CI->load->library('your_library');
Edit: NOTE: Check if your library file is capitalized inoyur folder structure like Libb.php
编辑: 注意:检查您的库文件是否大写inoyur文件夹结构,如
Libb.php
whenever you use libraries and helpers and need a built-in method from CI , use 无论何时使用库和帮助程序并且需要CI中的内置方法,请使用
$CI =& get_instance();
and then use it like so 然后像这样使用它
$CI->load->helper('url');
$CI->load->library('session');
$CI->config->item('base_url'); //...etc
see codeigniter.com/userguide2/general/creating_libraries.html for more info 有关详细信息,请参阅codeigniter.com/userguide2/general/creating_libraries.html
or for a better solution, you can use codeigniter + HMVC to be able to call a controller from another and avoid any conflicts and ease your troubleshooting see 或者为了更好的解决方案,您可以使用codeigniter + HMVC从另一个控制器调用控制器,避免任何冲突并简化您的故障排除
MVC vs HMVC for web application development MVC vs HMVC用于Web应用程序开发
Cheers ! 干杯!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.