drz5553 2019-05-24 14:01
浏览 141
已采纳

设置Composer /自动加载我的类的问题

I'm learning how Composer is working (new to dev ^^) But i'm struggling to fix my autoloading...

here's my composer.json :

      "autoload": {
        "psr-4": {
            "OCFram\\": "/../lib/",
            "App\\": "/../",
            "Model\\": "/../lib/vendors/",
            "Entity\\": "/../lib/vendors/",
            "FormBuilder\\": "/../lib/vendors/",
            "Slug\\": "/../lib/vendors/"
        }
      },

So for example :

Fatal error: Uncaught Error: Class 'App\Frontend\FrontendApplication' not found

Well, FrontendApplication path (from composer.json) : **

../App/Frontend/FrontendApplication.php

Here's the FrontendApplication.php with the namespace :

 <?php
 namespace App\Frontend;

 use \OCFram\Application;

 class FrontendApplication extends Application
 {
   public function __construct()
   {
      parent::__construct();

      $this->name = 'Frontend';
   } 

   public function run()
   {
      $controller = $this->getController();
      $controller->execute();

      $this->httpResponse->setPage($controller->page());
      $this->httpResponse->send();
   }
 }

Plus, i've , noticed this file (autoload_psr4.php) on vendor/composer :

 <?php

// autoload_psr4.php @generated by Composer

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

 return array(
     'Slug\\' => array('/lib/vendors'),
     'OCFram\\' => array('/lib'),
     'Model\\' => array('/lib/vendors'),
     'FormBuilder\\' => array('/lib/vendors'),
     'Entity\\' => array('/lib/vendors'),
     'App\\' => array('/'),
    );

Would appreciate some help :)

[EDIT]

So i changed the path from "App\": "/../" (which was no sense) to : "App\": "../",

NOW after another composer dump-autoload i get this :

                 <?php

                 // autoload_psr4.php @generated by Composer

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

                return array(
                'Slug\\' => array($baseDir . '/../lib/vendors'),
                'OCFram\\' => array($baseDir . '/../lib'),
                'Model\\' => array($baseDir . '/../lib/vendors'),
                'FormBuilder\\' => array($baseDir . '/../lib/vendors'),
                'Entity\\' => array($baseDir . '/../lib/vendors'),
                'App\\' => array($baseDir . '/..'),
                );

But still same problem when i try php index.php i get : Fatal error: Uncaught Error: Class 'App\Frontend\FrontendApplication' not found

  • 写回答

1条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥20 有人知道怎么将vsi格式的图片文件,转换为svs格式的文件吗
      • ¥15 历史模拟法计算var实验报告
      • ¥15 白鲸算法优化K值的VMD分解出错
      • ¥20 写一个基于52单片机用hc-05蓝牙模块控制28BYJ-48步进电机进行旋转,在手机蓝牙串口输入1019电机转半圈,输入2038电机转一圈,输入0复位的代码吗
      • ¥15 求51单片机8位数码管计时器程序
      • ¥20 matlab识别螺母边缘
      • ¥15 python 6x6游戏加登录、记录系统
      • ¥100 基于做一个模拟智慧路灯
      • ¥15 ME21N 创建采购成功并且生成采购订单号,但显示“快件文档更新已取消”,SM13看错误提示为如下截图:
      • ¥30 android 集成fmod实现变声功能中遇到的问题