pestleihui 发表于 2009-4-13 11:34:31

load->controller()中的一个类?

这里高手如云,向各位请教一个问题:
怎么从controller中的一个类里面,读取另外一个controller的类?或者是说怎么加载controller中例外一个类?

先感谢所有人.

yuwen002 发表于 2009-4-13 11:51:10

不能从一个控制器调用另外一个控制器

yuwen002 发表于 2009-4-13 11:55:03

你看看这里的各位老大们翻译的那本书。
那里很好的解释了。为什么不可以这样的。和解决方案

Hex 发表于 2009-4-13 12:24:29

是的,控制器不可以调用另外的控制器。

pestleihui 发表于 2009-4-13 14:03:47

谢谢各位的答案.
我用了 include_once, 导入想要的controller/testing, 然后new Testing();
但是出现错误:
all to a member function _assign_libraries() on a non-object in D:\projects\gene24\web\doc-root\system\libraries\Loader.php on line 1038.
其中的函数是:
function _ci_assign_to_models()
        {
                if (count($this->_ci_models) == 0)
                {
                        return;
                }
       
                if ($this->_ci_is_instance())
                {
                        $CI =& get_instance();
                        foreach ($this->_ci_models as $model)
                        {                       
                                $CI->$model->_assign_libraries();
                        }
                }
                else
                {               
                        foreach ($this->_ci_models as $model)
                        {                       
                                $this->$model->_assign_libraries();
                        }
                }
        }       
1308行是:$CI->$model->_assign_libraries();
请问这个问题怎么解决?

pestleihui 发表于 2009-4-13 14:05:36

请问那本书叫什么名字? 谢谢! 3# yuwen002

bnlt2009 发表于 2009-4-13 14:07:55

《PHP 敏捷开发框架 CodeIgniter》
应该是指这本,在公告和置顶的帖子里有

pestleihui 发表于 2009-4-13 14:30:36

谢谢你! 7# bnlt2009

Hex 发表于 2009-4-13 16:02:07

我已经说过了,控制器不能直接调用另外的控制器。
有这种需求的,应该从设计角度重新思考自己的项目。

pestleihui 发表于 2009-4-13 16:41:52

谢谢你们的好意见,但是这个问题必须得用调用controller的函数.
我的方法是:
include_once('models_users.php');
               
$class= new ReflectionClass('models_users');
// echo $class;
               
$methods = array();
foreach ($class->getMethods() as $method)
{
        $methods[] = $method->getName();
}
var_dump($methods);
就取得了例外一个函数的方法.
页: [1] 2
查看完整版本: load->controller()中的一个类?