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

      <small id='7Zcpc'></small><noframes id='7Zcpc'>

        <bdo id='7Zcpc'></bdo><ul id='7Zcpc'></ul>
      <tfoot id='7Zcpc'></tfoot>
      1. Laravel 4 - 包括一个“部分"视图中的视图(不使用 Blade 模板)

        时间:2023-11-01
          <tbody id='QW9DP'></tbody>

        <small id='QW9DP'></small><noframes id='QW9DP'>

        1. <tfoot id='QW9DP'></tfoot>

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

                  本文介绍了Laravel 4 - 包括一个“部分"视图中的视图(不使用 Blade 模板)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在 Laravel 3 中,我曾经这样做过.

                  In Laravel 3, I used to do this.

                  <?php render('partials.header'); ?>
                  

                  这是在PHP"视图中完成的,没有使用 Laravel 的 Blade 模板.

                  This was done in "PHP" views, without using Laravel's Blade templates.

                  在版本 4 中相当于什么?

                  What's the equivalent of this in version 4?

                  我试过了

                  <?php @include('partials.header'); ?>
                  

                  这不起作用.

                  如果我这样做

                  @include('partials.header')
                  

                  我必须将我的文件保存为.blade.php"

                  I have to save my file as ".blade.php"

                  如何在不使用刀片模板的情况下包含子视图"?

                  How do I include a "subview" without using the blade template?

                  推荐答案

                  在 Laravel 4 中,有多种方法可以在视图中包含视图.您的选择将取决于下面列出的任何一种结果...

                  There are different ways to include a view within a view in Laravel 4. Your choice will depend on any one of the outcomes outlined below...

                  您可以在适当的控制器中编译(渲染)部分视图,并使用 $data[''] 数组将这些视图传递给主视图.

                  You can compile (render) the partial views in the appropriate Controller, and pass these views to the Main View using the $data[''] array.

                  随着观看次数的增加,这可能会变得乏味,但是嘿,至少有很大的灵活性:)

                  This may become tedious as the number of views increase, but hey, at least there's a lot of flexibility :)

                  示例见下面的代码:

                  ...
                  
                  public function showMyView()
                  {
                     /* Header partial view */
                     $data['header'] = View::make('partials.header');
                  
                     /* Flexible enough for any kind of partial views you require (e.g. a Header Menu partial view) */
                     $data['header_menu'] = View::make('partials.header_menu'); 
                  
                     /* Footer partial view */
                     $data['footer'] = View::make('partials.footer');
                  
                     return View::make('myView', $data);
                  }
                  
                  ...
                  

                  查看

                  您可以按如下方式包含上述部分内容(在您的视图代码中的任何位置):

                  View

                  You can include the partials above as follows (at any position in your View code):

                  <html>  
                  <head></head>   
                  <body>
                  
                  <!-- include partial views -->
                  <?php echo ($header) ?>  
                  <?php echo ($header_menu) ?>  
                  
                  <div id="main-content-area"></div>  
                  
                  <?php echo ($footer) ?>  
                  
                  </body>  
                  </html>
                  

                  您的部分视图现在将添加到您的主视图中.

                  Your partial views will now be added to your main View.

                  其实有一个比使用上面的方法更简单的方法:只需在视图的 html 中包含这个...

                  There's actually a much easier way than using the method above: Simply include this in the html of the view...

                  <html>  
                  <head></head>   
                  <body>
                  
                  <!-- include partial view: header -->
                  <?php echo View::make('partials.header') ?>
                  
                     <div id="main-content-area">
                     </div>
                  
                  <!-- include partial view: footer -->
                  <?php echo View::make('partials.footer') ?>
                  
                  </body>  
                  </html>
                  

                  确保部分的文件夹结构是 [views/partials/header.php] 以便为 Laravel 的 View::make() 函数提供正确的文件路径.

                  Make sure that the folder structure for the partials is [views/partials/header.php] in order to provide the correct file-path to the View::make() function of Laravel.

                  如果您尝试在控制器中传递 $data['page_title']嵌套视图将不会接收数据.
                  要将数据传递给这些嵌套视图,您需要这样做:

                  If you try to pass the $data['page_title'] in a controller, the nested views wont receive the data.
                  To pass data to these nested views you need to do it like this:

                  <html>  
                  <head></head>   
                  <body>
                  
                  <?php
                     /* Pass page title to header partial view */
                     $data ['page_title'] = "My awesome website";  
                     echo View::make('partials.header', $data); 
                  ?>
                  
                  <div id="main-content-area"></div>
                  
                  <?php echo View::make('partials.footer') ?>
                  
                  </body>  
                  </html>
                  

                  注意

                  问题明确指出:不使用 Blade 模板",所以我确保给出一个不包含任何 Blade 模板代码的解决方案.

                  NOTE

                  The question clearly stated: "Without using Blade template", so I have made sure to give a solution that does not include any Blade templating code.

                  这篇关于Laravel 4 - 包括一个“部分"视图中的视图(不使用 Blade 模板)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Laravel 4.2 说我的应用程序正在生产中.我该如何关闭它? 下一篇:可以修改由 artisan migrate 命令创建的模板吗?

                  相关文章

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

                    <legend id='Qpjz6'><style id='Qpjz6'><dir id='Qpjz6'><q id='Qpjz6'></q></dir></style></legend>

                      <bdo id='Qpjz6'></bdo><ul id='Qpjz6'></ul>

                    <small id='Qpjz6'></small><noframes id='Qpjz6'>