We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

LibsController handler class cannot be loaded phalcon

Hi, I'm building a project based on INVO. I don't know this error appears since when but I get it on every request, no matter what controller is. My project is still working fine excepts it prints this error on every request.

Furthermore, I searched whole project but got nothing relevant to LibsController or just "Libs". So I don't know what's wrong with my project.

This is error log. For each request there are 2 of this log printed.

LibsController handler class cannot be loaded\n#0 [internal function]: Phalcon\\Mvc\\Dispatcher->_throwDispatchException('LibsController ...', 2)\n#1 [internal function]: Phalcon\\Dispatcher->dispatch()\n#2 /path/to/invo/public/index.php(32): Phalcon\\Mvc\\Application->handle(NULL)\n#3 {main}

index.php

error_reporting(E_ALL);

use Phalcon\Mvc\Application;
use Phalcon\Config\Adapter\Ini as ConfigIni;
use Phalcon\Config\Adapter\Json as ConfigJson;
use Phalcon\Debug;

try {
    $debug = new Debug();
    $debug->listen();
    define('APP_PATH', realpath('..') . '/');

    /**
     * Read the configuration
     */
    $config = new ConfigJson(APP_PATH . 'app/config/config.json');
    if (is_readable(APP_PATH . 'app/config/config.dev.json')) {
        $override = new ConfigJson(APP_PATH . 'app/config/config.dev.json');
        $config->merge($override);
    }

    /**
     * Auto-loader configuration
     */
    require APP_PATH . 'app/config/loader.php';

    $application = new Application(new Services($config));

    // NGINX - PHP-FPM already set PATH_INFO variable to handle route
    echo $application->handle(!empty($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : null)->getContent();
} catch (Exception $e){
    echo $e->getMessage() . '<br>';
    echo '<pre>' . $e->getTraceAsString() . '</pre>';
}

config.json

{
    "databases": {
        "a": {
            "dbname": "test1",
            "adapter": "Mysql",
            "host": "localhost",
            "username": "root",
            "password": "123456",
            "charset": "utf8"
        },
        "b": {
            "dbname": "test2",
            "adapter": "Mysql",
            "host": "localhost",
            "username": "root",
            "password": "123456",
            "charset": "utf8"
        }
    },
    "application": {
        "controllersDir": "app/controllers/",
        "modelsDir"     : "app/models/",
        "viewsDir"      : "app/views/",
        "pluginsDir"    : "app/plugins/",
        "formsDir"      : "app/forms/",
        "libraryDir"    : "app/library/",
        "baseUri"       : "/"
    }
}

loader.php

$loader = new \Phalcon\Loader();

/**
 * We're a registering a set of directories taken from the configuration file
 */
$loader->registerDirs([
    APP_PATH . $config->application->controllersDir,
    APP_PATH . $config->application->pluginsDir,
    APP_PATH . $config->application->libraryDir,
    APP_PATH . $config->application->modelsDir,
    APP_PATH . $config->application->formsDir
])->register();

$loader->registerClasses([
    'Services' => APP_PATH . 'app/Services.php'
]);

If anyone needs more info, please tell me.

Update: Now I known. I have some assets in public/libs/ . For unknown reason, phalcon treats them as routers, althought browser's still loading those assets successful. Is this a bug?



85.5k
edited Jan '19

i assume you call your URL like doamin.ff/libs/, phalcon listens for a route there and is trying to load a controller to handle the request.

check carefully router configuration

你的控制器没有加命名空间吧?