Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
251 views
in Technique[技术] by (71.8m points)

php - How to load view from alternative directory in Laravel 4

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
});

My directory structure:

-app

--themes

---default

---azure

I need to load views from localhost/laravel/app/themes/default folder. Please explain this.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is entirely possible with Laravel 4. What you're after is actually the view environment. You can register namespace hints or just extra locations that the finder will cascade too. Take a look here

You'd add a location like so:

View::addLocation('/path/to/your/views');

It might be easier if you namespace them though, just in case you have conflicting file names as your path is appended to the array so it will only cascade so far until it finds an appropriate match. Namespaced views are loaded with the double colon syntax.

View::addNamespace('theme', '/path/to/themes/views');

return View::make('theme::view.name');

You can also give addNamespace an array of view paths instead of a single path.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...