在 zend 框架中构建动态菜单时页面和路由映射的最佳实践
虽然我很清楚这个话题可能已经出现过很多次了,但我仍然认为我看待它的角度是不同的。
我有一个 ZF 1.10.8 项目,本质上是 ContentController
来管理我所说的静态页面(无论如何不是那么静态),例如关于我们
、联系我们
、products
和 NewsController
用于文章、教程和所有文章。
我发现动态菜单可以解决客户的很多抱怨,并可以更自由地更改网站内容。
目前我只有一个主菜单栏,它是一个部分菜单栏(在layouts/scripts/partials/_mainmenu.phtml文件夹下),我在系统中存在的每个布局中调用它。
现在,如果我采用动态方式,并且创建了一个新链接,比如说 category
,如何将类别页面映射到路线(路线位于 /application/configs/routes.ini 中),因为 url 将是数据库菜单表
中链接的值?
第一个想法是将所有内容更改为由 NewsController
处理的 resource
,甚至将 关于我们
更改为一篇文章。引用为静态页面需要不同的视图,我不知道如何处理它们。
我对自己的思维方式感到有点不舒服。
有人能指出我正确的方向吗?如果你会怎么做? joomla 人是怎么做到的?
感谢您的阅读......
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.
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.
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?
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.
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?
thanks for reading.....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我正在使用命名路由在菜单中构建
由路由处理的精确模块/控制器/操作映射 中的链接
模块引导程序中定义的模块特定路由。
我无法向您提供更多信息,因为我当前的路线实施过于棘手和脆弱。必须首先对其进行大量重构。
i am using named routes to build links in menu
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.
我的方法是使用一个插件,在
routeStartup()
中检查数据库中当前 URI 是否存在,如果找到 URI,则使用此函数添加正确的路由:我不有无限数量的控制器和模块,因此该函数的参数被硬编码到插件中,但它们可以轻松地存储在数据库中的行中,以更加动态。
添加插件意味着在
routeStartup()
完成后,新的正确路由可用于调度操作。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: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.