doulei6778 2014-03-10 15:48
浏览 292
已采纳

在Laravel中设置我自己的库时出现ReflectionException错误

I am a Laravel newbie. I'm following a tutorial where someone sets up a custom library to verify forms. My directory structure is setup like this:

Lara
----->app----->Acme----->Services
                   ----->Validators
----->bootstrap
----->public
----->vendor

I get an error: ReflectionException Class Acme\Services\TasksValidator does not exist

I suspect it's in my TaskController which starts like this:

<?php
use \Acme\Services\TaskCreatorService;

class TasksController extends BaseController{
        protected $taskCreator;

        public function __construct(TaskCreatorService $taskCreator){
            $this->taskCreator = $taskCreator;

        }

        public function index(){
        $tasks = Task::with('user')->get();
        $users = User::lists('username', 'id');

What am I doing wrong? I've added the following in my composer.json under autoload

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

I've also run: composer dump-autoload -o

My TaskCreatorService file begins like this:

<?php
namespace Acme\Services;

use Acme\Validators\TaskValidator;
use Acme\Validators\ValidationException;
use Task;

class TaskCreatorService{
    protected $validator;
  • 写回答

1条回答 默认 最新

  • dongzhisang5342 2014-03-10 16:21
    关注

    You are requiring

    use Acme\Validators\TaskValidator;
    

    And using in your class:

    \Acme\Services\TasksValidator (with an S)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 C# 使用DEVMOD设置打印机首选项
  • ¥15 想用@vueuse 把项目动态改成深色主题,localStorge里面的vueuse-color-scheme一开始就给我改成了dark,不知道什么原因(相关搜索:背景颜色)
  • ¥20 OPENVPN连接问题
  • ¥15 flask实现搜索框访问数据库
  • ¥15 mrk3399刷完安卓11后投屏调试只能显示一个设备
  • ¥100 如何用js写一个游戏云存档
  • ¥15 ansys fluent计算闪退
  • ¥15 有关wireshark抓包的问题
  • ¥15 需要写计算过程,不要写代码,求解答,数据都在图上
  • ¥15 向数据表用newid方式插入GUID问题