Php Zend框架添加路由

Php Zend框架添加路由,php,zend-framework,Php,Zend Framework,我需要将路由添加到Zend Framwork应用程序 我想显示数据库中的所有帖子,其中catagory=控制器名称 domain.com/action domian.com/drama domain.com/thriller 我该怎么做?我查阅了ZF Routes的文档。但是没有找到解决方案。要做到这一点,您必须在application.ini中添加类似的内容 resources.router.routes.category.type = "Zend_Controller_Router_Ro

我需要将路由添加到Zend Framwork应用程序

我想显示数据库中的所有帖子,其中catagory=控制器名称

domain.com/action 
domian.com/drama
domain.com/thriller

我该怎么做?我查阅了ZF Routes的文档。但是没有找到解决方案。

要做到这一点,您必须在application.ini中添加类似的内容

resources.router.routes.category.type = "Zend_Controller_Router_Route"
resources.router.routes.category.route = ":category"
resources.router.routes.category.defaults.module = "default"
resources.router.routes.category.defaults.controller = "index"
resources.router.routes.category.defaults.action = "index"
这样,所有不匹配的控制器都将作为索引控制器索引操作中的类别参数进行定向。请记住处理无效的类别名称和触发器404


另外,这里有一篇关于

的好文章,可以使用bootstrap.php文件中的addRoute()方法来完成

// Retrieve the front controller from the bootstrap registry
$FrontController = $this->getResource('FrontController');
$router = $FrontController->getRouter();

$router->addRoute('genre', 
                  new Zend_Controller_Router_Route(
        ':genre',array( 'controller' => 'index' , 'action' => 'index'  )) );
在控制器中获取流派

echo $this->getRequest()->getParam('genre')