【问题标题】:Laravel 5.1 modular blade templateLaravel 5.1 模块化刀片模板
【发布时间】:2015-11-08 14:02:32
【问题描述】:

我在 Laravel 5.1 中使用下面博客中描述的模块化结构 http://ziyahanalbeniz.blogspot.com.tr/2015/03/modular-structure-in-laravel-5.html

事实上,我有一个模块用户,其结构如下:

- 控制器

- 模型

- 翻译

- 意见
-> index.blade.php
-> register.blade.php

在我的 Views 目录中,我有一个 index.blade.php 文件和一个 register.blade.php 文件。 在我的 index.blade.php 文件中,我使用: @include('register') 以便在我的索引 php 文件中包含注册文件。 但是在调用我的索引文件时,我得到一个 view not found 异常。

我遇到了一些麻烦,这是我必须在@include 中添加的正确路径。 @include('user.register') 也不起作用。有任何想法吗?谢谢

【问题讨论】:

    标签: laravel-5 laravel-5.1


    【解决方案1】:

    您应该包含相对于resources/view 的路径(无论您从哪里调用),将“/”替换为“.”。

    例如:

    yourproject/resources/views/template.php
    yourproject/resources/views/module1/main.php
    yourproject/resources/views/module1/foo.php
    yourproject/resources/views/module2/main.php
    yourproject/resources/views/module2/bar.php
    

    应包含为:

    @include('template');
    @include('module1.main');
    @include('module1.foo');
    @include('module2.main');
    @include('module2.bar');
    

    请记住,当您使用@include 时,它会复制文件,就像您复制并粘贴它一样。 @include 不会扩展文件,因此在使用时不能替换 @yield@section 标签。

    换句话说,调用文件成为父文件。如果你想建立一个子视图,你应该改用@extends

    干杯

    【讨论】:

      猜你喜欢
      • 2015-12-01
      • 2016-03-11
      • 2015-10-27
      • 2016-06-11
      • 2013-04-29
      • 2017-04-03
      • 2018-05-31
      • 2014-02-05
      相关资源
      最近更新 更多