我正在为SocialEngine包开发一个模块,我希望能够指定多个自定义路由。
目前我正在使用以下内容编辑模块目录中的Bootstrap.php文件;
class Courses_Bootstrap extends Engine_Application_Bootstrap_Abstract
{
protected function _initRouter(){
$fc = Zend_Controller_Front::getInstance();
$router = $fc->getRouter();
$router->addRoute('courses', new Zend_Controller_Router_Route('courses/activity/:activity_id', array('module' => 'courses', 'controller' => 'index','action' => 'activity')));
$router->addRoute('courses', new Zend_Controller_Router_Route('courses/course/edit/:course_id', array('module' => 'courses', 'controller' => 'course','action' => 'edit')));
$router->addRoute('courses', new Zend_Controller_Router_Route('courses/course/create/:course_id', array('module' => 'courses', 'controller' => 'course','action' => 'create')));
return $router;
}
}
然而,当我指定多于1条路线时,似乎所有路线都停止传递自定义变量(course_id或activity_id)
我正在检索变量,如下所示;
$course_id = $this->getRequest()->getParam("course_id");
我从这里采取了这个方法; http://tjgamble.com/2011/04/adding-custom-routes-to-your-socialengine-4-modules/
非常感谢,
安迪
答案 0 :(得分:3)
你必须给他们不同的名字:
$router->addRoute('courses_activitiy', new Zend_Controller_Router_Route('courses/activity/:activity_id', array('module' => 'courses', 'controller' => 'index','action' => 'activity')));
$router->addRoute('courses_course', new Zend_Controller_Router_Route('courses/course/edit/:course_id', array('module' => 'courses', 'controller' => 'course','action' => 'edit')));
$router->addRoute('courses_create', new Zend_Controller_Router_Route('courses/course/create/:course_id', array('module' => 'courses', 'controller' => 'course','action' => 'create')));