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.