V
V
Viktor Yanyshev2017-11-15 17:56:01
Composer
Viktor Yanyshev, 2017-11-15 17:56:01

Composer doesn't load classes specified in autoload, why?

index.php

require_once '../vendor/autoload.php';
$router = components\Router::getInstance();

router
namespace components;
use controllers;

class Router {
....
public function init($routes) {
.....
 $obj = new $controller_name;  // HomeController
 $result = call_user_func($obj->$controller[1]); // index
.....

composer.json
After adding psr was:
composer dumpautoload -o
and
composer dumpautoload
"autoload": {
        "psr-0": {
            "components\\": "components/",
            "controllers\\": "controllers/",
            "models\\": "models/"
        }
    }

Structure:
./components
./controllers
./models
./web/
./web/index.php
Error:
Fatal error: Class 'HomeController' not found

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav B, 2017-11-15
@villiwalla

Fatal error: Class 'HomeController' not found

you have 'HomeController' in your controller_name variable without a namespace, and I can assume that you actually have it in your controllers namespace. In this case, the composer has nothing to do with it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question