![](/img/trans.png)
[英]Zend framework 2 call action from other action of the same controller
[英]Zend framework : no other Action except index action in the controller is callable
我有两个动作的控制器文件,即:
class IndexController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
// action body
}
public function doLoginAction()
{
// action body
}
}
及其相应的视图文件。 即当我点击http://www.mydomain.com/index时,它将加载索引视图。 我面临的问题是,当我尝试访问此控制器的索引操作时,它将加载相应的视图,但是当我尝试执行dologin操作时,它将给出错误
http://www.mydomain.com/index/dologin
* 消息:操作“ dologin”不存在,也没有被困在__call()*中
请求参数:
array (
'controller' => 'index',
'action' => 'dologin',
'module' => 'default',
)
当我尝试使用另一个控制器和动作时,也会发生同样的情况。 index动作对于该控制器也可以正常运行,但不能在该控制器中执行任何其他操作。
PS:我已经在Apache配置文件中配置了mod_rewrite模块和AllowOverride ALL
驼峰式动作名称应以破折号形式表示为params。 因此,doLoginAction()将响应/ default / index / do-login,而不是dologin。 如果希望该URL是dologin,则应将操作重命名为dologinAction()。
您还可以在控制器级别使用连字符(-)分隔的url。
假设您需要这样的网址:
http://www.mydomain.com/do-some-stuff/my-stuff/
然后,您的控制器应命名为:
DoSomeStuffController (as class name) && DoSomeStuffController.php (as controller file name)
和
myStuffAction() (as your method name)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.