Laravel 4.1 - 调用View Composers类 - ReflectionException类不存在

时间:2014-03-28 01:01:00

标签: laravel

尝试调用View Composer类时,我一直收到此错误:类MyApp / Composers / HeaderComposer不存在

/app/MyApp/Composers/HeaderComposer.php:

<?php namespace MyApp\Composers;

class HeaderComposer {

    public function compose($view) {

        $view->with('foo', 'foobar');

    }
}

composer.json:

    "psr-4": {
        "MyApp\\" : "app/MyApp/"
    }

routes.php文件:

View::composer('layouts.default', 'MyApp/Composers/HeaderComposer');

供应商/作曲家/ autoload_psr4.php

<?php

// autoload_psr4.php @generated by Composer

$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);

return array(
'MyApp\\' => array($baseDir . '/app/MyApp'),
'Monolog\\' => array($vendorDir . '/monolog/monolog/src/Monolog'),
);

我还能错过什么?

谢谢,

火腿

1 个答案:

答案 0 :(得分:0)

更改

中的正斜杠
View::composer('layouts.default', 'MyApp/Composers/HeaderComposer');

反斜杠

View::composer('layouts.default', 'MyApp\Composers\HeaderComposer');

它会起作用