调用另一个控制器的动作 [英] call action of another controller
本文介绍了调用另一个控制器的动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个网格视图,我想从另一个动作控制器获取列的值.现在我在控制器 1 中有这个
i have a grid view and i would like to get value of column from another action controller. at now i have this in controller 1
array(
'name'=>'title',
'value'=>array($this,'Action2'),
),
我收到此错误:
controller1 and its behaviors do not have a method or closure named "Action2".
如果我用controller2"替换 $this
if i replace $this with "controller2"
array(
'name'=>'title',
'value'=>array('controller2','Action2'),
),
我收到这个错误
call_user_func_array() [<a href='function.call-user-func-array'>function.call-user-func-array</a>]: First argument is expected to be a valid callback, 'controller2::action2' was given
也许这是不好的做法,但这可行吗?
maybe this is bad practice but is this feasible?
推荐答案
以这种方式使用控制器操作是不好的做法.最好将您的代码放在模型的方法中.但如果您仍然想这样做,这里有一种方法:
It's bad practice to use controller actions this way. Better place your code in model's method. But if you still want to do this, here is one way:
'value' => function() {
list($controller) = Yii::app()->createController('controllerId');
return $controller->actionTest();
}
这是另一个:
'value' => function() {
$controller = new TestController('test');
return $controller->actionTest();
}
这篇关于调用另一个控制器的动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文