Laravel 中的命名空间视图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19819915/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Namespacing views in Laravel
提问by Mark Lewis
I was referred to Juggling Larger Laravel Applicationsand I'm havihng trouble getting
我被转介到Juggling Larger Laravel Applications并且我在获取时遇到了麻烦
View::addNamespace('Marketing', __DIR__.'/../Views')
to work in one of my sub-app directories where the viewsare located at /var/www/myapp.com/app/MyApp/Marketing/Views
在我的子应用程序目录之一中工作,其中视图位于/var/www/myapp.com/app/MyApp/Marketing/Views
Placing this code in my /var/www/myapp.com/app/MyApp/Marketing/Providers/MarketingServiceProvider.php
将此代码放在我的/var/www/myapp.com/app/MyApp/Marketing/Providers/MarketingServiceProvider.php
<?php namespace MyApp\Marketing\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\View;
class MarketingServiceProvider extends ServiceProvider
{
public function register()
{
}
public function boot()
{
require_once(__DIR__.'/../routes.php');
View::addNamespace('Marketing', __DIR__.'/../Views');
}
}
and referencing it in my routes file like
并在我的路由文件中引用它,例如
Route::group(array('domain' => array('www.myapp.dev')), function()
{
return View::make('Marketing::index');
});
results in No hint path defined for [Marketing].
导致没有为 [Marketing] 定义提示路径。
I've also added
我也加了
MyApp\Marketing\Providers\MarketingServiceProvider
to the provider's config array.
到提供者的配置数组。
Lastly, I'm using psr-0 in composer
最后,我在作曲家中使用 psr-0
"autoload": {
"psr-0": {
"MyApp": "app/"
},
采纳答案by Mark Lewis
And I'm stupid... the problem wasn't what I thought it was…
而且我很笨……问题不是我想的那样……
Route::group(array('domain' => array('www.myapp.dev')), function()
{
return View::make('Marketing::index');
});
Changing my route to that above fixes everything. I accidentally had www.myapp.dev in an additional array which was causing all of the unexpected results.
将我的路线更改为上述路线可以解决所有问题。我不小心将 www.myapp.dev 放在了一个额外的数组中,这导致了所有意想不到的结果。
回答by Gravy
Im confused too... Whats wrong with:
我也很困惑......有什么问题:
Route::group(array('domain' => array('www.myapp.dev')), function()
{
return View::make('marketing.index');
});
and storing your marketing index view as: app/views/marketing/index.blade.php
?
和存储你的营销索引视图为:app/views/marketing/index.blade.php
?
回答by Phil Sturgeon
Why on earth would you try to namespace a view? Just put them in a folder called "marketing"...
你到底为什么要尝试命名视图?只需将它们放在一个名为“营销”的文件夹中...