实现菜单的“选择” Yii 中的链接
我有两个模板可以集成到 yii 中 - 我的前端网站和我的 CMS。
我的前端网站有由 CMS(数据库)生成的顶部菜单
CMS 顶部菜单是我的静态菜单。 (“管理页面”、“管理用户”、“管理产品”)虽然此菜单是静态的,但我仍然想将选定的类分配给相应的顶部菜单项。
例如:如果我正在管理网站上的某些页面,则应突出显示并选择“管理页面”链接。我该怎么办呢?我需要自己编写一些东西,或者 yii 中是否有我需要参考的现有函数?
提前致谢 yii新手
I have two templates to integrate into yii - my front end website and my CMS.
My front end website has top menu that is generated by CMS (database)
CMS top menu which is static menu by me. ("Manage pages", "Manage users", "Manage products") although this menu is static I still want to assign a selected class to the appropriate top menu item.
Eg: If I'm managing some pages on the site the "Mange pages" link should be highlighted and selected. How would I go about this? Something I need to code myself or is there a existing function in yii that i need to refer to?
Thanks in advance
Yii newbie
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
创建一个 css 类来更改对象的背景以突出显示它。
在各个页面的视图中,只需使菜单项具有该特定类即可。
Make a css class that changes the background of the object to highlight it.
In your views for the various pages just make the menu item have that particular class.
我所做的是在我的 Controller (
AdminController extends Controller
) 类中拥有多个“菜单”功能。每个都构建 CMenu 需要的数组,并且我根据我传递给函数的内容。例如:您可以在看起来像控制器或操作或 URL 请求的地方执行此操作,并将相应的菜单项设置为活动状态。这只是一个例子。
然后在我看来,如果我想在“管理页面”处于活动状态时呈现菜单,我可以使用 Controller 类中的函数设置布局的菜单:(
这假设您有
public $menu=array();< /code> 在您的控制器中声明,并查看博客示例以了解其工作原理
:)
我希望这能给您一些指导!
What I do is have multiple "menu" functions in my Controller (
AdminController extends Controller
) class. Each one builds the array the CMenu needs, and I set the active one based on what I passed in to the function. For instance:You could do this where it looks like the Controller or Action or URL request and sets the appropriate menu item active as well. This is just an example.
Then in my view, if I want to render the menu with "Manage pages" active, I set my layout's Menu using the function in my Controller class:
(This assumes that you have
public $menu=array();
declared in your Controller, and as well. Look at the Blog example to see how this works:)
I hope this gives you some direction!