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

strange bug with controller class name first letter

after dispatching any route, Dispatcher::getControllerClass() eats first letter from controller class name. Following simple code:

<?PHP
use Phalcon\Di;
use Phalcon\Events\Manager;
use Phalcon\Mvc\Dispatcher;
use Phalcon\Mvc\Router;

$di = new Di\FactoryDefault();

$oRouter = new Router(false);
$oRouter->setDI($di);

$oRouter->add('/:controller', array(
    'controller' => 1,
    'action' => 'index',
));

$oEventManager = new Manager();
$oEventManager->attach('dispatch:beforeDispatch', function(){
    return false;
});

$oDispatcher = new Dispatcher();

$oDispatcher->setDI($di);

$oDispatcher->setEventsManager($oEventManager);

$oRouter->handle('/test');

$oDispatcher->setControllerName($oRouter->getControllerName());
$oDispatcher->setActionName($oRouter->getActionName());

$oDispatcher->dispatch();

echo $oDispatcher->getControllerClass() . PHP_EOL;

echoes estController instead of TestController Same thing happens when using namespaces. For example, when trying to dispatch same route on module under namespace: App\Modules\Api\Web\Controllers phalcon will try to load class with FQDN App\Modules\Api\Web\Controllers\estController instead of App\Modules\Api\Web\Controllers\TestController This is especially strange considering that Dispatcher::getControllerName() returns test exactly as it supplsed to.



4.7k

Which Version of Phalcon are you using? This Bug was fixed in Version 2 of phalcon



2.4k
Accepted
answer

updated to 2.0.4. bug disappears.