-1

Hello guys i have problem with autoloading my class with composer. On Linux all work perfect, but now my boss change env and set Windows. All this work on linux but windows show newbie fatal error:

Fatal error: Class 'AbstractController' not found in D:\xampp\htdocs\ikacFw\frontController.php on line 7

Common to see my composer.json and stucture for better picture on problem.

Stucture is :

frontController.php

-- vendor
----- Doctrine
----- Ikac
--------- Components
---------- Mvc
------------- Controller

Am trying to load all data from vendor directory.

Composer.json

{
    "autoload": {
        "psr-0": {
            "vendor": ""
        }
    }
}

Also new component i add manual. Like this :

$loader = require_once 'vendor/autoload.php'; 
$loader->add('vendor', "Ikac");

Okay next when i try to call :

<?php
require_once 'vendor/autoload.php'; 

use Ikac\Mvc\Controller;


$a = new AbstractController();

I get error "not found".

My class AbstractController contain defined namespace but dont work again. Like test i do this:

    <?php
    //vendor/Ikac/Mvc/Controller/AbstractController.php

    namespace Ikac\Mvc\Controller;

    class AbstractController {

        function __construct() {
            echo __CLASS__;
        }
    }

    ?>

I do from cmd composer dump-autoload, install, but dont work. All this perfect work on linux but here wont. Any idea how to fix this or where i do mistake.

Thanks guys!

SLOVED:

{
    "autoload": {
        "psr-0": {
            "": "vendor/"
        }
    }
}
4

2 回答 2

0

您的自动加载声明是错误的。

您永远不需要在任何自动加载中包含供应商文件夹。供应商文件夹将包含所有依赖项的自动加载,并且 - 如果已配置 - 还包含您自己的类。

您可以使用 Composer 为您自己的类创建自动加载。只需包含正确的信息。但是从您当前的信息中,我无​​法推断出正确的信息。

于 2013-11-17T15:46:21.893 回答
0

那么你应该做

<?php
require_once 'vendor/autoload.php'; 

use Ikac\Mvc\Controller\AbstractController;


$a = new AbstractController();
于 2013-11-17T15:39:04.847 回答