Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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.



2.3k

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



1.1k
Accepted
answer

updated to 2.0.4. bug disappears.