<i id='4Mm2q'><tr id='4Mm2q'><dt id='4Mm2q'><q id='4Mm2q'><span id='4Mm2q'><b id='4Mm2q'><form id='4Mm2q'><ins id='4Mm2q'></ins><ul id='4Mm2q'></ul><sub id='4Mm2q'></sub></form><legend id='4Mm2q'></legend><bdo id='4Mm2q'><pre id='4Mm2q'><center id='4Mm2q'></center></pre></bdo></b><th id='4Mm2q'></th></span></q></dt></tr></i><div id='4Mm2q'><tfoot id='4Mm2q'></tfoot><dl id='4Mm2q'><fieldset id='4Mm2q'></fieldset></dl></div>
          <bdo id='4Mm2q'></bdo><ul id='4Mm2q'></ul>
        <legend id='4Mm2q'><style id='4Mm2q'><dir id='4Mm2q'><q id='4Mm2q'></q></dir></style></legend>

        <tfoot id='4Mm2q'></tfoot>

        <small id='4Mm2q'></small><noframes id='4Mm2q'>

        Laravel 中 View Composer 和 Creator 的区别?

        时间:2023-10-02
      1. <i id='F0NYF'><tr id='F0NYF'><dt id='F0NYF'><q id='F0NYF'><span id='F0NYF'><b id='F0NYF'><form id='F0NYF'><ins id='F0NYF'></ins><ul id='F0NYF'></ul><sub id='F0NYF'></sub></form><legend id='F0NYF'></legend><bdo id='F0NYF'><pre id='F0NYF'><center id='F0NYF'></center></pre></bdo></b><th id='F0NYF'></th></span></q></dt></tr></i><div id='F0NYF'><tfoot id='F0NYF'></tfoot><dl id='F0NYF'><fieldset id='F0NYF'></fieldset></dl></div>
        <tfoot id='F0NYF'></tfoot>
            <legend id='F0NYF'><style id='F0NYF'><dir id='F0NYF'><q id='F0NYF'></q></dir></style></legend>

              <tbody id='F0NYF'></tbody>
              <bdo id='F0NYF'></bdo><ul id='F0NYF'></ul>
              • <small id='F0NYF'></small><noframes id='F0NYF'>

                  本文介绍了Laravel 中 View Composer 和 Creator 的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  根据 Laravel 4 文档.

                  作曲家是:

                  视图合成器是在渲染视图时调用的回调或类方法.如果每次在整个应用程序中呈现视图时都希望将数据绑定到给定视图,则视图编写器可以将该代码组织到一个位置.因此,视图编辑器的功能可能类似于视图模型"或演示者".

                  View composers are callbacks or class methods that are called when a view is rendered. If you have data that you want bound to a given view each time that view is rendered throughout your application, a view composer can organize that code into a single location. Therefore, view composers may function like "view models" or "presenters".

                  View::composer('profile', function($view)
                  {
                      $view->with('count', User::count());
                  });
                  

                  还有

                  创作者是:

                  视图创建者的工作方式几乎与视图编辑器完全一样;然而,当视图被实例化时,它们会立即被触发.注册一个视图创建者,简单使用creator方法

                  View creators work almost exactly like view composers; however, they are fired immediately when the view is instantiated. To register a view creator, simple use the creator method

                  View::creator('profile', function($view)
                  {
                      $view->with('count', User::count());
                  });
                  

                  所以问题是:有什么区别?

                  推荐答案

                  当您使用 View::creator 时,您有机会覆盖控制器中的视图变量.像这样:

                  When you use View::creator you have the chance to override the variables of view in the controller. Like this:

                  View::creator('layout', function($view) {
                      $view->with('foo', 'bar');
                  });
                  
                  // in controller
                  return View::make('layout')->with('foo', 'not bar at all');
                  
                  // it's defined as 'not bar at all' in the view
                  

                  -

                  View::composer('hello', function($view) {
                      $view->with('foo', 'bar');
                  });
                  
                  // in controller
                  return View::make('hello')->with('foo', 'not bar at all');
                  
                  // it's defined as 'bar' in the view
                  

                  这篇关于Laravel 中 View Composer 和 Creator 的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:codeigniter:将数组从控制器传递到视图 下一篇:将变量从控制器传递到视图 - Laravel

                  相关文章

                  最新文章

                  <i id='2SGO4'><tr id='2SGO4'><dt id='2SGO4'><q id='2SGO4'><span id='2SGO4'><b id='2SGO4'><form id='2SGO4'><ins id='2SGO4'></ins><ul id='2SGO4'></ul><sub id='2SGO4'></sub></form><legend id='2SGO4'></legend><bdo id='2SGO4'><pre id='2SGO4'><center id='2SGO4'></center></pre></bdo></b><th id='2SGO4'></th></span></q></dt></tr></i><div id='2SGO4'><tfoot id='2SGO4'></tfoot><dl id='2SGO4'><fieldset id='2SGO4'></fieldset></dl></div>

                  <small id='2SGO4'></small><noframes id='2SGO4'>

                  <legend id='2SGO4'><style id='2SGO4'><dir id='2SGO4'><q id='2SGO4'></q></dir></style></legend>
                • <tfoot id='2SGO4'></tfoot>

                    • <bdo id='2SGO4'></bdo><ul id='2SGO4'></ul>