尝试调用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'),
);
我还能错过什么?
谢谢,
火腿
答案 0 :(得分:0)
更改
中的正斜杠View::composer('layouts.default', 'MyApp/Composers/HeaderComposer');
反斜杠
View::composer('layouts.default', 'MyApp\Composers\HeaderComposer');
它会起作用