我从Laravel 4.1中得到以下错误。Laravel 4.1 ReflectionException
ReflectionException 类Acme \ Services \ TaskCreatorService不存在。
在此先感谢您的帮助。
下面是定义类的代码。它位于app\Acme\Services
。
<?php namespace Acme\Services;
use \Acme\Validators\TaskValidator;
use \Acme\Validators\ValidationException;
use \Acme\Validators\Validator;
class TaskCreatorService {
protected $validator;
public function __construct(TaskValidator $validator) {
$this->validator = $validator;
}
public function make(array $attributes) {
//determone whether data is valid
if ($this->validator->isValid($attributes)) {
Task::create([
'title' => $attributes['title'],
'body' => $attributes['body'],
'user_id' => $attributes['assign']
]);
return true;
}
throw new ValidationException('Task validation failed', $this->validator-getErrors());
//create the new task
//
//if not throw exception
}
}
我也曾在自动加载这部分增加composer.json
。
"psr-0": {
"Acme": "app/"
}
看起来像任何代码试图使用你的类没有配置为自动加载该名称空间 – Phil
正如安东尼奥所说,虽然你不需要做一个'composer dump-autoload'在使用PSR-0/4,当你第一次编辑'composer.json'文件来指定这个时,你需要这样做,这样Composer才能真正了解这个PSR规则。这是问题吗? – alexrussell