[英]How to set views folder destination during runtime in laravel
I'm trying to build a saas application
(saas here means software as a service) in laravel 5.3. 我正在尝试在laravel 5.3中构建一个
saas application
(saas这里意味着软件即服务)。 I'm trying to implement the view folder destination by extending the ViewServiceProvider
. 我正在尝试通过扩展
ViewServiceProvider
来实现视图文件夹目标。 For example I'm having two different themes for two different domains. 例如,我对两个不同的域有两个不同的主题。 I'm having the set of HTML code in views in different folders, something like this:
我在不同文件夹中的视图中有一组HTML代码,如下所示:
View
----| Theme One
--------| Navbar
--------| Sliders
--------| Tabs
--------| Parallax
--------| Iconbox
--------| template.blade.php
----| Theme Two
--------| Navbar
--------| Sliders
--------| Tabs
--------| Parallax
--------| Iconbox
--------| template.blade.php
Now I want to define folder structure dynamically for these domains so that it should show the modules of their respective theme. 现在我想为这些域动态定义文件夹结构,以便它应该显示各自主题的模块。 Like suppose if I want to include sub-view of Navbar I just have to write
就像假设我想要包含Navbar的子视图一样,我只需要编写
@include('Navbar')
and it should access the respective theme Navbar folder or sub-view. 它应该访问相应的主题Navbar文件夹或子视图。 To implement this I'm extending the
ViewServiceProvider
and in config/app.php
I'm just commenting out the ViewServiceProvider
and added the WebViewServiceProvider
which I made, it is not setting the destination, here is my code: 为了实现这一点,我正在扩展
ViewServiceProvider
并在config/app.php
我只是注释掉了ViewServiceProvider
并添加了我做的WebViewServiceProvider
,它没有设置目标,这是我的代码:
namespace Nitseditor\System\Providers;
use Illuminate\View\FileViewFinder;
use Illuminate\View\ViewServiceProvider;
use Nitseditor\System\Models\Domain;
class WebViewServiceProvider extends ViewServiceProvider
{
/**
* Register View Folder
*
* @return void
*/
public function registerViewFinder()
{
$this->app->bind('view.finder', function ($app) {
$paths = $app['config']['view.paths'];
$http_req = php_sapi_name() == 'cli' ? 'noetic.com' : $this->app['request']->server('HTTP_HOST');
$domainName = explode(":", $http_req)[0];
$domain = Domain::where('domain_name', $domainName)->first();
if($domain)
{
foreach ($domain->themes as $theme)
{
$paths = 'Nitseditor\System\Resources\Views\Themes\\' . $theme->theme_name;
}
}
return new FileViewFinder($app['files'], array(base_path($paths)));
});
}
}
My config\\app.php looks like: 我的config \\ app.php看起来像:
// Illuminate\View\ViewServiceProvider::class,
Nitseditor\System\Providers\WebViewServiceProvider::class,
while executing and checking through controller I can see the destination paths of views are same as default 在执行和检查控制器时,我可以看到视图的目标路径与默认路径相同
class DomainController extends Controller {
public function checkDomain()
{
$app = App::make('config');
dd($app);
}
}
Edit 编辑
well I tried executing without conditional statements it happens to be same. 好吧,我尝试在没有条件语句的情况下执行它恰好相同。
public function registerViewFinder()
{
$this->app->bind('view.finder', function ($app) {
$paths = 'Nitseditor\System\Resources\Views\Themes\Themeone';
return new FileViewFinder($app['files'], array(base_path($paths)));
});
}
Help me out with this. 帮助我解决这个问题。
Well I kept on trying to die dump the code and tried checking $app
array. 好吧,我继续试图甩掉代码并尝试检查
$app
数组。 I guess when I try doing App::make::('config')
laravel collects information from the configuration files and shows the configuration array of app in which dynamic configuration are not being displayed. 我想当我尝试做
App::make::('config')
laravel从配置文件中收集信息,并显示app的配置数组,其中没有显示动态配置。
Then I simply tried checking my views: 然后我只是尝试检查我的观点:
return view('template');
It displayed the blade file/views exactly what I required, well it might help someone. 它显示了我所需要的刀片文件/视图,它可能对某人有所帮助。 Don't panic with
不要惊慌失措
$app = App::make('config');
dd($app);
Cheers!! 干杯!!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.