如何从Laravel 4中的备用目录加载视图 [英] How to load view from alternative directory in Laravel 4
问题描述
在Laravel 4应用程序的根目录中,我有一个文件夹 themes
.在 themes
文件夹中,我有 default
和 azure
.
如何通过特定路径从此 themes/default
文件夹访问视图.
In my Laravel 4 application's root directory, I have a folder themes
. Inside the themes
folder, I have default
and azure
.
How can I access view from this themes/default
folder in a specific route.
Route::get('{slug}', function($slug) {
// make view from themes/default here
});
我的目录结构:
-app
-主题
---默认
---天蓝色
我需要从localhost/laravel/app/themes/default
文件夹加载视图.请解释一下.
I need to load views from localhost/laravel/app/themes/default
folder. Please explain this.
推荐答案
在这里,我没有从 public
文件夹访问我的项目.取而代之的是,我从项目根目录本身进行访问.
Here I am not accessing my project from public
folder. Instead of this I am accessing from project root itself.
我看过有关 Using alternative path for views
的论坛讨论此处.但是我对此并不感到困惑.讨论的解决方案是,
I have seen a forum discussion about Using alternative path for views
here. But I am little confused about this.The discussed solution was,
您将添加 location
之类的
You'd add a location
like,
View::addLocation('/path/to/your/views');
然后为主题添加 namespace
,
Then add namespace
for theme,
View::addNamespace('theme', '/path/to/themes/views');
然后渲染它,
return View::make('theme::view.name');
/path/to/
的值是什么?
我可以在不更改路径的情况下在不同的操作系统中使用同一项目吗?
Can I use the same project in different operating system without changing the path?
是的,我们可以使用以下内容来实现
Yes, we can do this using the following,
将以下内容放入app/start/global.php
View::addLocation(app('path').'/themes/default');
View::addNamespace('theme', app('path').'/themes/default');
然后使用默认方式调用视图,
Then call view like the default way,
return View::make('page');
这将从project_directory/app/themes/defualt
文件夹中呈现page.php
或page.blade.php
文件.
This will render page.php
or page.blade.php
file from project_directory/app/themes/defualt
folder.
这篇关于如何从Laravel 4中的备用目录加载视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!