简体   繁体   English

在zend框架中构建动态菜单时的页面和路线最佳实践映射

[英]Best Practice mapping of pages and routes when building dynamic menu in zend framework

while i'm well awared this topic might have come a number of time, i still think that the perspective from which i'm looking at it is different. 尽管我很清楚这个主题可能已经出现很多次,但我仍然认为我所看的观点是不同的。

I have a ZF 1.10.8 project whith essentially ContentController to manage what i call static pages (not so static anyway) like about us , contact us , products and NewsController for articles, tutorials, all writeups. 我有一个ZF 1.10.8项目,实际上是ContentController来管理我所谓的静态页面(无论如何也不是静态的),例如about uscontact usproductsNewsController以获得文章,教程和所有文章。

i've found that having a dynamic menu will solve a lot of complains from the client and gives more freedom changing the content of the site. 我发现拥有动态菜单将解决客户的许多抱怨,并为更改网站内容提供更大的自由度。

currently i only a main menu bar which is a partial (under layouts/scripts/partials/_mainmenu.phtml folder) which i call in every layout that exists in the system. 目前,我仅是一个主菜单栏,该菜单栏是系统中存在的每个布局中调用的一部分(在layouts / scripts / partials / _mainmenu.phtml文件夹下)。

Now if i go dynamic, and a new link is created let's say category , how to map the category page to a route (routes are in /application/configs/routes.ini) since the url would be the value of the link in the menu table in the database? 现在,如果我变得动态起来,并创建了一个新链接,我们说category ,那么如何将类别页面映射到路由(路由位于/application/configs/routes.ini中),因为url将是链接中的值数据库中的menu table

the first thought is to change everything to resource handled by the NewsController to even about us will be an article in that case.Since those that i referenced as static pages require different view i wouldn't know how to handle them. 在这种情况下,首先想到的是将NewsController处理的所有resource都更改为about us的内容。由于我引用为静态页面的那些页面需要不同的视图,因此我不知道如何处理它们。

I'm kind of uncomfortable with my way of thinking it. 我对自己的思考方式感到不舒服。

Can anyone point me to the right direction please? 谁能指出我正确的方向? How would you do if? 如果要怎么办? how joomla guys do it? joomla家伙怎么做?

thanks for reading..... 谢谢阅读.....

i am using named routes to build links in menu 我正在使用命名路线在菜单中建立链接

new Zend_Navigation_Page_Mvc(array(
    'label'      => $category->getTitle(),
    'route'      => 'catalog-category',
    'params'     => array('id' => $category->getId()),
));

exact module/controller/action mapping handled by routes module specific routes defined in module bootstrap. 路由由模块引导程序中定义的模块特定路由处理的确切模块/控制器/动作映射。

i cant give you more on this as my current routes implementation are too tricky and fragile. 由于目前的路线实施过于棘手和脆弱,因此我无法提供更多信息。 must heavily refactor it first. 必须首先对其进行大量重构。

My approach is to have a plugin that in routeStartup() checks for the existence of the current URI in a database, if the URI is found then the correct route is added using this function: 我的方法是有一个插件,该插件在routeStartup()检查数据库中当前URI的存在,如果找到URI,则使用此函数添加正确的路由:

protected function _createRoute($route, $name, $action = "index", $controller = "index", $module = "default", $params)
{
    $router = Zend_Controller_Front::getInstance()->getRouter();

    $defaults = array('controller' => $controller,
                      'action' => $action,
                      "module" => $module);

    $route = new Zend_Controller_Router_Route($route, array_merge($defaults, $params));

            $router->addRoute("region", $route);    
}

I don't have a limitless number of controllers and modules so the parameters for this function are hard coded into the plugin, but they could easily for stored against the row in the DB to be more dynamic. 我没有无限数量的控制器和模块,因此此功能的参数已硬编码到插件中,但是可以很容易地将它们存储在数据库中的行中,以提高动态性。

Adding the plugin do this means that after routeStartup() is complete the new correct route is available for the dispatch operation. 添加插件意味着执行routeStartup()之后,新的正确路由可用于调度操作。

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

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