Laravel 4,针对@include查看作曲家 [英] Laravel 4, view composers against @include

查看:76
本文介绍了Laravel 4,针对@include查看作曲家的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到是否像这样将第二个参数传递给@include:

I noticed if I pass a second parameter to @include like this:

@include('sidebars.pages', array('categories' => Category::all()))

然后可以像在Rails中一样在视图中复制渲染局部的概念,并在局部内部渲染局部的概念.

Then it is possible to replicate the concept of render partials within views and render partials within partials like in Rails.

我仍然需要具有此功能的查看作曲家吗?

Do I still need view composers with this functionality?

感谢您的帮助!

推荐答案

虽然有可能不是@include的书面使用.这样做时,我会格外谨慎,就我个人而言,我不会在您的观点范围内称呼模型.从路由或控制器绑定所需的数据.利用演示者执行任何演示逻辑,以确保您的视图绝对干净.

While that may be possible it's not the documented use of @include. I'd use caution when doing it like that, and personally, I wouldn't be calling a model within your view. Bind the data you require from your route or controller. Make use of a presenter to perform any presentation logic to keep your views absolutely clean.

@include将所有当前定义的变量注入到嵌套的局部视图中.因此,如果将所有类别都绑定到父视图,然后使用@include('sidebars.pages'),则该视图也将具有绑定到其上的类别.

@include injects all currently defined variables into the nested partial view. So if you bound all the categories to the parent view, then used @include('sidebars.pages'), that view would also have the categories bound to it.

这篇关于Laravel 4,针对@include查看作曲家的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆