Php 如何在ZF1路由中使用多个参数
我试图向我的Zend Framework 1应用程序添加新路由。但它似乎把我的两个情人理解为一个。我怎样才能解决这个问题Php 如何在ZF1路由中使用多个参数,php,zend-framework,routes,zend-route,Php,Zend Framework,Routes,Zend Route,我试图向我的Zend Framework 1应用程序添加新路由。但它似乎把我的两个情人理解为一个。我怎样才能解决这个问题 $route = new Zend_Controller_Router_Route(':name-:type', array('controller' => 'tour', 'action' => 'index')); $route = $routeLang->chain($route); $router->addRoute('tour', $rout
$route = new Zend_Controller_Router_Route(':name-:type', array('controller' => 'tour', 'action' => 'index'));
$route = $routeLang->chain($route);
$router->addRoute('tour', $route);
让我把你的问题再说一遍,以便其他人能很快理解: 如何通过破折号(“-”)将“name”和“type”参数一起传递,这样如果转到url:“tour/index/sampleName-sampleType”,Zend可以识别名称是“sampleName”,类型是“sampleType” 您需要:Zend_控制器_路由器_路由_正则表达式() 如果希望url匹配:“www.example.com/sampleName-sampleType”
protected function _initRoutes ()
{
$this->bootstrap('frontController');
$front = $this->getResource('frontController');
$router = $front->getRouter();
$route = new Zend_Controller_Router_Route_Regex('(.+)-(.+)', array('controller' => 'tour', 'action' => 'index'), array(1 => 'name', 2=>'type'), '%s-%s');
$router->addRoute('tour', $route);
}
protected function _initRoutes ()
{
$this->bootstrap('frontController');
$front = $this->getResource('frontController');
$router = $front->getRouter();
$route = new Zend_Controller_Router_Route_Regex('(.+)-tour-(.+)', array('controller' => 'tour', 'action' => 'index'), array(1 => 'name', 2=>'type'), '%s-tour-%s');
$router->addRoute('tour', $route);
}
或者如果您想匹配:“www.example.com/sampleName-tour-sampleType”
protected function _initRoutes ()
{
$this->bootstrap('frontController');
$front = $this->getResource('frontController');
$router = $front->getRouter();
$route = new Zend_Controller_Router_Route_Regex('(.+)-(.+)', array('controller' => 'tour', 'action' => 'index'), array(1 => 'name', 2=>'type'), '%s-%s');
$router->addRoute('tour', $route);
}
protected function _initRoutes ()
{
$this->bootstrap('frontController');
$front = $this->getResource('frontController');
$router = $front->getRouter();
$route = new Zend_Controller_Router_Route_Regex('(.+)-tour-(.+)', array('controller' => 'tour', 'action' => 'index'), array(1 => 'name', 2=>'type'), '%s-tour-%s');
$router->addRoute('tour', $route);
}
在控制器“巡更”,操作“索引”中打印出来:
echo '<br>Name is: ' . $this->getParam('name') . '<br>Type is: ' . $this->getParam('type');
在控制器中打印出来:
echo '<br>Name is: ' . $this->getParam('name') . '<br>Type is: ' . $this->getParam('type');
echo'
名称为:'$此->getParam('name')。'
类型为:'$此->getParam('type');
我的代码在调用$this->url(数组('name'=>'bla','type'=>123),'tour')时抛出一个错误;似乎你不能在路线中使用破折号。我发现问题出在这里,对不起,我需要先澄清你的问题,如果我错了,请纠正我。是否要在“名称”和“类型”之间添加破折号,并将它们作为一个参数一起发送?在转到:tour/index/firstString secondString之后,您希望Zend识别名称为“firstString”,类型为“secondString”?ye,我希望最终url为www.example.com/adventure-tour-1234,我希望adventure tour作为一个参数,1234作为另一个参数。我已经编辑了我的答案。希望它能解决您的问题:)