我正在創建一個控制器,它將從數據庫中提取畫家的信息並顯示它:PainterController
。我有一個像這樣定義它:Zend自定義路由不被識別爲控制器
<?php
class PainterController extends Zend_Controller_Action
{
public function init()
{
//setup painter route
$router = $this->getFrontController()->getRouter();
$router->addRoute(
'painter',
new Zend_Controller_Router_Route(
'painter/:id',
array(
'controller' => 'painter',
'action' => 'info'
)
)
);
}
public function indexAction()
{
//index
}
public function infoAction()
{
//info was requested for given ID
}
}
?>
正如你所看到的,一個途徑是建立接受像domain.com/painter/12
凡在本例中,ID 12傳遞到infoAction什麼。
然而,當我訪問這樣的URL我的路線是不被認可,而不是我得到:
Message: Action "2" does not exist and was not trapped in __call()
Stack trace:
#0 /home/httpd/vhosts/xxx.com/subdomains/peter/httpdocs/library/Zend/Controller/Action.php(515): Zend_Controller_Action->__call('2Action', Array)
#1 /home/httpd/vhosts/xxx.com/subdomains/peter/httpdocs/library/Zend/Controller/Dispatcher/Standard.php(295): Zend_Controller_Action->dispatch('2Action')
#2 /home/httpd/vhosts/xxx.com/subdomains/peter/httpdocs/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#3 /home/httpd/vhosts/xxx.com/subdomains/peter/httpdocs/library/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch()
#4 /home/httpd/vhosts/xxx.com/subdomains/peter/httpdocs/library/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#5 /home/httpd/vhosts/xxx.com/subdomains/peter/httpdocs/public/index.php(25): Zend_Application->run()
#6 {main}
Request Parameters:
array (
'controller' => 'painter',
'action' => '2',
'module' => 'default',
)
有沒有人對爲什麼會發生這種情況的線索?
(僅供參考,我意識到,這些文件都位於公共目錄中,這是由於一個共享的虛擬主機的限制。該文件使用的.htaccess保護。這是毫無關係的問題。)
更新:在引導程序中定義時,上述內容似乎有效。但是,我不喜歡在引導中加入很多邏輯。是否可以在控制器內部定義與控制器相關的路由?
+1擊敗我。 ;-) –
同上!不能總是贏得;) –