Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Model view controller Codeigniter:如何调用控制器文件夹中控制器中的外部控制器_Model View Controller_Codeigniter_Controller - Fatal编程技术网

Model view controller Codeigniter:如何调用控制器文件夹中控制器中的外部控制器

Model view controller Codeigniter:如何调用控制器文件夹中控制器中的外部控制器,model-view-controller,codeigniter,controller,Model View Controller,Codeigniter,Controller,我正在使用php中的codeigniter,我的问题是如何调用位于controllers文件夹中的控制器中的外部控制器 //this file is Controller2.php in controllers folder class Controller2 extends CI_Controller { function one() { // Some code goes here.. } } //and now this file is Controll

我正在使用php中的codeigniter,我的问题是如何调用位于controllers文件夹中的控制器中的外部控制器

    //this file is Controller2.php in controllers folder
class Controller2 extends CI_Controller
{
function one()
   {
      // Some code goes here..
   }
}


//and now this file is Controller1.php which is also in controllers folder


class Controller1 extends CI_Controller
{
   function one()
   {
      // I want to load Controller2 here
   }
}
请指导我,因为我在谷歌搜索中浪费了太多时间

提前谢谢


卡姆兰

你不能,或者更确切地说,你不应该。需要在两个不同控制器中使用的任何功能都应移动到库或帮助文件中

您可以(但不是使用默认功能)使用类似的东西,您应该使用CodeIgniter扩展:


关于这个扩展,有很多例子和一个很好的帖子。

看看这个。感谢您快速回复。。或者,如果我想将所需控制器的方法移动到模型中,那么这有意义吗?当然,有可能。在严格的MVC模型中,多个模型用于将数据映射(建模)到控制器可用的格式-实际上,这通常意味着模型是数据库交互/处理的所在地。事实上,Codeigniter对这些事情非常宽容,所以我在模型中使用了相当多的非数据库逻辑,因为我很懒。tl;博士:是的,如果比较容易的话,你可以把它移到模型上。