我想要url example.com/invoice/id/5
创建动作
function indexAction(){
echo "test";
}
现在我尝试从url 访问此操作
example.com/invoice/
或example.com/invoice/index
并通过参数
example.com/invoice/id/5
这里我得到了错误,因为Zend试图渲染
id.phtml
我的问题是如何拥有url example.com/invoice/id/5
而不使用example.com/invoice/index/id/5
默认Zend Route如下:http://www.example.com/controller/action/param_name/param_value/param_name_1/param_name_1_value
对于自定义URL,您必须在Bootstrap.php中定义自Zf1起的路由。
$frontController=Zend_Controller_Front::getInstance();$router=$frontController->getRouter();
$router->addRoute(
'someidentifier',
new Zend_Controller_Router_Route(
'/invoice/:id',
array(
'controller'=>'invoice',
'action'=>'index'
)
)
);
如果是ZF2,我认为您必须在Module.php、onBootstrap函数中定义自定义路由,并连接到eventManager。