【问题标题】:Laravel change view root path from middlewareLaravel 从中间件更改视图根路径
【发布时间】:2017-04-13 18:31:10
【问题描述】:
//middleware
if ( Helpers::isMobile() ) {
     //how to change view path root here, from views -> views/mobile
}

//desktop layout
/views/index.blade.php

//mobile layout
/views/mobile/index.blade.php

我有一个网站需要在检测到手机时更改视图根路径。

  1. Helper里面有手机检测功能

  2. 我希望在中间件中运行它

  3. 是否可以从配置中禁用此中间件? (config/setting.php)

【问题讨论】:

标签: php laravel


【解决方案1】:

要在运行时更改路径,您必须创建 FileViewFinder 的新实例。

您可以使用此代码

$finder = new \Illuminate\View\FileViewFinder(app()['files'], array(app_path().'/your path'));
View::setFinder($finder);

或者您可以使用此代码将新位置添加到您的视图文件夹

\View::addLocation('location to your view folder')

【讨论】:

    猜你喜欢
    • 2019-01-23
    • 2013-08-08
    • 1970-01-01
    • 2016-02-09
    • 1970-01-01
    • 2016-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多