简体   繁体   English

Laravel中的命名空间视图

[英]Namespacing views in Laravel

I was referred to Juggling Larger Laravel Applications and I'm havihng trouble getting 我被告知处理大型Laravel应用程序 ,但遇到麻烦

View::addNamespace('Marketing', __DIR__.'/../Views')

to work in one of my sub-app directories where the views are 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]. 结果没有为[营销]定义提示路径。

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/"
    },

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放在另一个数组中,这导致了所有意外结果。

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

Why on earth would you try to namespace a view? 您到底为什么要尝试为视图命名空间? Just put them in a folder called "marketing"... 只需将它们放在名为“营销”的文件夹中即可...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM