Php Zend索引操作参数
我想要urlPhp Zend索引操作参数,php,zend-framework,zend-route,Php,Zend Framework,Zend Route,我想要urlexample.com/invoice/id/5 创建操作 function indexAction(){ echo "test"; } 现在我尝试从url访问此操作 example.com/invoice/或example.com/invoice/index 并传递参数 example.com/invoice/id/5 这里我得到了一个错误,因为Zend试图渲染 id.phtml 我的问题是,默认情况下,如何使用urlexample.com/invoice/id/5,而不
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路由如下:
对于自定义URL,必须从Zf1开始在Bootstrap.php中定义路由
$frontController=Zend_Controller_Front::getInstance();
$router=$frontController->getRouter()
如果是ZF2,我认为您必须在Module.php、onBootstrap函数中定义自定义路由并附加到eventManager。将此添加到控制器操作方法?否。如果使用的是ZF1,则需要将代码添加到Bootstrap.php->Method\u initRoutes()。您在控制器中所做的是只需要添加索引操作,$this->getParam('id')将获得id。
$router->addRoute(
'someidentifier',
new Zend_Controller_Router_Route(
'/invoice/:id',
array(
'controller'=>'invoice',
'action'=>'index'
)
)
);