![](/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.