简体   繁体   English

kohana kostache 部分逻辑

[英]kohana kostache partial logic

Started an project using kostache.使用 kostache 启动了一个项目。

I have made some partials like banner,navigatons and footer in my class View_Layout with extends kostache_layout .我在我的类 View_Layout 中使用了 extends kostache_layout 制作了一些部分,如横幅、导航和页脚。 Partials work fine on each page.部分在每个页面上都能正常工作。

One problem.一个问题。 The navigation show always the same links.导航显示始终相同的链接。 My goal is to show links that are appropriate to the user who is logged.我的目标是显示适合登录用户的链接。 How can I put logic in the partial of navigation?如何在导航部分放置逻辑? I know I can write functions in the View_Layout class but View_Layout must know the user role?我知道我可以在 View_Layout 类中编写函数,但 View_Layout 必须知道用户角色?

Hope somebody can help me.希望有人可以帮助我。

In mustache, partials inherit from the surrounding template's variable stack.在 mustache 中,部分继承自周围模板的变量堆栈。 You'd need to do this logic in your view class.您需要在视图类中执行此逻辑。 If different pages need different links, do that in your specific view class.如果不同的页面需要不同的链接,请在您的特定视图类中执行此操作。

Option 1: evolve your views选项 1:发展您的观点

The best option would be to expand the capabilities of your views.最好的选择是扩展视图的功能。 Actually in MVC-inspired patterns the views should be instances which handle UI logic and can choose from which (usually, more then one) templates to create the response.实际上,在受 MVC 启发的模式中,视图应该是处理 UI 逻辑的实例,并且可以从哪些(通常是多个)模板中进行选择来创建响应。 If that response even needs to be a HTML .. maybe a simple HTP header would be enough.如果该响应甚至需要是 HTML .. 也许一个简单的 HTP 标头就足够了。

The default toolset in Kohana is geared towards very simple usecases, but it is possible to expand it. Kohana 中的默认工具集面向非常简单的用例,但可以对其进行扩展。

My recommendation would be start using fully implemented views.我的建议是开始使用完全实现的视图。

Option 2: use HMVC选项 2:使用 HMVC

Alternatively, you can utilize HMVC capabilities in Kohana.或者,您可以利用 Kohana 中的 HMVC 功能。 This would mean, that you have one or few "main controllers", which then create sub-requests.这意味着,您有一个或几个“主控制器”,然后它们会创建子请求。 The responses from those requests is passed in/bound to the template, which said controller supervise.来自这些请求的响应被传入/绑定到所述控制器监督的模板。

In you particular case the menu would be governed by separate sub-controller.在您的特殊情况下,菜单将由单独的子控制器管理。

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

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