Lithium框架:如何在布局中获取控制器名称
我在一个锂布局文件中,我想回显当前控制器的名称(稍后用作 CSS 类)。如何获取当前控制器名称?
谢谢, 艾诺
I'm in a lithium layout file and I'd like to echo the name of the current controller (to use as a CSS class later). How can I obtain the current controller name?
Thanks,
aeno
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想你的意思是你在视图中?
如果是这样,那么获取控制器或路由/请求的其他部分非常简单......
这将为您提供控制器,但您可以从您的路线中获取您需要的任何内容。因此,假设您有一条像...这样的路线,
您可以在您的视图中使用以下两种方式:
或者您可以有一条更漂亮的路线,例如..
这将适用于像这样的网址:
现在您可以做类似的事情...
获取网址的“区域”部分等。您明白了。
I assume you mean you are in a View?
If so, it's pretty simple to get the controller or other parts of the route/request ...
That will get you the Controller but you can get just about anything from your route you'd need. So assuming you have a route like ...
You can use both of the following in your view:
Or you could have a fancier route like ..
This would be for a url like:
Now you can do something like ...
To get the "area" portion of the url, etc. You get the idea.
可以在任何 Lithium 布局或视图中使用以下代码来查找当前的 Controller,将其转换为合适的 CSS 类名称,并将其设置为 div 的 class 属性:
请求类记录在此处: http://li3.me/docs/lithium/action/Request
The following code can be used in any Lithium layout or view to look up the current Controller, convert it to a suitable CSS class name, and set it as the class attribute of a div:
The request class is documented here: http://li3.me/docs/lithium/action/Request