I'm creating a controller which will pull information of a painter from a database and display it: PainterController
. I have defined it like so:
<?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
}
}
?>
As you can see, a route is setup to accept anything like domain.com/painter/12
where in this example the id 12 is passed to the infoAction.
Yet, when I visit such URL I the route is not being recognized, instead I get:
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',
)
Does anyone have a clue on why this would happen?
(FYI, I realize that the files are located in a public directory, this is due to a shared webhost constraint. The files are protected using .htaccess. This is unrelated to the question.)
Update: it appears that the above does work when defined in the bootstrap. However, I do not like to put a lot of logic in the bootstrap. Is it possible to define controller related routes inside the controller itself?