Nit*_*mar 2 laravel laravel-blade laravel-5.3 laravel-views
我正在尝试在laravel 5.3. 我已经建立了很少的服务提供商来收集这些特定网站的域名、正在使用的主题和数据库。现在我正在尝试使用view structurethrough实现页面service provider。例如,现在我为两个不同的域设置了两个不同的主题。我在不同文件夹的视图中有一组 HTML 代码,如下所示:
View
----| Theme One
--------| Navbar
--------| Sliders
--------| Tabs
--------| Parallax
--------| Iconbox
--------| template.blade.php
----| Theme Two
--------| Navbar
--------| Sliders
--------| Tabs
--------| Parallax
--------| Iconbox
--------| template.blade.php
Run Code Online (Sandbox Code Playgroud)
现在我想为这些域动态定义文件夹结构,以便它应该显示它们各自主题的模块。就像假设如果我想包含 Navbar 的子视图,我只需要写
@include('Navbar')
Run Code Online (Sandbox Code Playgroud)
它应该访问相应的主题导航栏文件夹或子视图。我想过创建一个服务提供者并尝试通过配置来设置这样的路径:
public function boot()
{
$this->webView = $this->setPath();
$this->app->singleton('webView', function()
{
return $this->webView;
});
}
public function setPath()
{
$themename = App::make('themename')
if($themename)
{
$setpath = "..Path\Views\" . $themename;
Config::set('view.paths', $setpath);
return null;
}
else
{
return "Not found";
}
}
Run Code Online (Sandbox Code Playgroud)
但是我猜当应用程序引导时它会忽略配置,我知道必须有更好的方法来实现这一点。请指导我。
首先创建一个ViewServiceProvider在App\Providers这样或复制Illuminate\View\ViewServiceProvider在app/Providers与这样的变化
<?php
namespace App\Providers;
use Illuminate\View\FileViewFinder;
use Illuminate\View\ViewServiceProvider as ConcreteViewServiceProvider;
class ViewServiceProvider extends ConcreteViewServiceProvider
{
/**
* Register the view finder implementation.
*
* @return void
*/
public function registerViewFinder()
{
$this->app->bind('view.finder', function ($app) {
$paths = $app['config']['view.paths'];
//change your paths here
foreach ($paths as &$path)
{
$path .= time();//change with your requirement here I am adding time value with all path
}
return new FileViewFinder($app['files'], $paths);
});
}
}
Run Code Online (Sandbox Code Playgroud)
然后Illuminate\View\ViewServiceProvider::class,用App\Providers\ViewServiceProvider::class,in替换你的config/app.php。这将解决问题。
| 归档时间: |
|
| 查看次数: |
1771 次 |
| 最近记录: |