简体   繁体   English

Laravel 4.1 ReflectionException

[英]Laravel 4.1 ReflectionException

I get the following error from Laravel 4.1. 我从Laravel 4.1中收到以下错误。

ReflectionException Class Acme\\Services\\TaskCreatorService does not exist. ReflectionException类Acme \\ Services \\ TaskCreatorService不存在。

Thanks in advance for any help. 在此先感谢您的帮助。

Below is the code defining the class. 下面是定义类的代码。 It is found in app\\Acme\\Services . 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
    }
}

I have also add this to composer.json in the autoload section. 我也将其添加到autoload部分的composer.json中。

    "psr-0": {
        "Acme": "app/"
    }

For me, in my case, following did work! 对我而言,按照我的意愿做的工作!

composer dump-autoload

I found it with a little explanation in the following link 我在以下链接中找到了一些解释

Hope it will be helpful! 希望对您有所帮助!

Laravel is really harder for newbies to catch up with, specially for the people who don't know Symfony or Ruby-on-Rails techniques! Laravel对于新手来说真的很难追上,特别是对于那些不了解Symfony或Ruby-on-Rails技术的人!

Good Luck guys! 祝大家好运!

Having your PSR-0 namespace 具有您的PSR-0名称空间

"Acme": "app/"

Your class file must be: 您的课程文件必须是:

/var/www/appdir/app/Acme/Services/TaskCreatorService.php

And you have to 而且你必须

composer dump-autoload

Once, when you created the PSR-0 namespace. 一次,当您创建PSR-0名称空间时。 Check the file 检查文件

/var/www/appdir/vendor/composer/autoload_psr0.php

And check if your namespace is there. 并检查您的名称空间是否存在。

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

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