繁体   English   中英

Zend Framework:需要帮助来设置路由

[英]Zend Framework: Need help setting up Routing

我如何如下设置路由

这些与标准路由一起使用

/posts            => index action (listing)
/posts/view       => view action (individual post)
/posts/add        => add action
/posts/edit       => edit action

这些呢?

可以基于1个或多个查询字符串以任意顺序过滤/posts 例如。

/ posts / tagged / tag1 / posts / tagged / tag1 / timeframe / 1w => fyi。 1w表示1周/ posts / timeframe / 1w / tagged / tag1 =>可以按任意顺序/ posts / sortby / dtposted =>可以添加更多选项

我该如何处理? 我试过了

$route = new Zend_Controller_Router_Route(
    'posts/*',
    array(
        'controller' => 'posts',
        'action' => 'index'
    )
);
$router->addRoute('postsIndex', $route);

但是,对于cos,所有到posts/*路由都到达索引控制器。 不是我想要的

如果您自然使用适当的命名约定,则无需为这些url使用路由。

class PostsController extends Zend_Controller_Action{
    public function viewAction(){
    }
    public function editAction(){
    }
    public function addAction(){
    }
    public function indexAction(){
    }
}

我建议回到基础知识,并在尝试理解路由之前学习控制器模型和视图在zend框架中的工作方式:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM