向 codeigniter 控制器添加上下文相关菜单
我为我的网站创建了一个通用的“页面”控制器。这些页面主要提供静态信息,它们从数据库中提取页面内容的最新版本以及更新日期。每个页面上都有一个部分菜单和一个资源菜单。部分菜单由页面所在站点的逻辑部分决定。资源菜单包含与该页面、文档、站外链接、日历事件链接等相关资源的链接。这些资源是特定于页面的,也可以拉取来自数据库。
目前,页面控制器生成它们并将它们放置在视图中,但我正在关注其他可能只有一个、两个或没有菜单的控制器的工作。我是否应该继续将菜单选择和生成作为页面控制器的功能并将其复制粘贴到新控制器?或者我应该以某种方式将菜单查找和生成功能分解到其他对象(库、帮助程序或插件)中?如果是这样我应该如何打破它?或者我还应该如何实施它?
I have created a generic "Page" controller for my site. These pages serve up mostly static information, they pull the most recent version of the page contents, and the update date from a database. On each page they have a section menu and a resource menu. The section menu is dictated by what logical section of the site the page resides in. The resource menu holds links to resources associated with that page, documents, offsite-links, links to calender events, etc. These resources are page specific and also pulled from a database.
Currently the Page controller generates them and places them in the view, but I am staring work on other controllers that may have only one, both, or none of the menus. Should I continue having the menu selection and generation be a function of the Page controller and copy paste it to new controllers? Or should I somehow break out the menu lookup and generation functions into some other object (library, helper, or plugin)? And if so how should I break it out? Or how else should I implement it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以做几件事,但要记住的重要一点是尝试并拥有一次代码,因此对于菜单,您不想复制并粘贴它。
如果您根据用户权限或其他内容定义菜单,您可以在视图中检查这些内容,例如:
如果您想根据页面或各种内容更改菜单,您还可以从控制器向视图发送参数。
不需要创建库、助手或插件。
You can do several things but the important thing to remember is to try and have the code once, so for the menu you dont want to copy and paste it.
If you are defining a menu based on user permission's or something you can check these things in the view for example:
You can also send parameters to the view from the controller if you want to change the menu depending on the page or a variety of things.
There should be no need to make a library, helper or plugin.