laravel从带有实际点的文件夹名称加载视图 [英] laravel load view from a folder name with actual dot
本文介绍了laravel从带有实际点的文件夹名称加载视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在创建一个多域Laravel应用,因此我的视图文件位于每个域的单独文件夹中.例如,以下内容:
I am creating a multi-domain Laravel app, so my view files are in separate folders per domain. For example, the following:
return view('pages/' . $_SERVER['SERVER_NAME'] . '/public/home', []);
应在下面加载视图
pages/domain.com/public/home.blade.php
但是它尝试加载
pages/domain/co/public/home.blade.php
由于点符号.
我该如何解决?
推荐答案
如果名称中包含点,则需要添加视图命名空间来为特定文件夹设置提示.
You'd need to add a view namespace to set up hints for a particular folder if there're dots in the name.
$domain = 'domain.com';
View::addNamespace($domain, config('view.paths')[0]."/{$domain}/");
Route::get('example', function() use ($domain) {
return view("{$domain}::home");
});
您可以使用base_path('resources/views')
代替上面的config('view.paths')[0]
中的示例,如果有人重新排序或更改config('view.paths')
You could use base_path('resources/views')
instead of in the example above config('view.paths')[0]
which is probably a bit more sensible in case someone reorders or changes the value of config('view.paths')
这篇关于laravel从带有实际点的文件夹名称加载视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文