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

URL.COM/username

Hola yo necesitaria realizar lo siguiente

Si ingreso una URl que no existe en ningun controlador ejemplo url.com/username

que me lleve al controlador x y a la accion %username% ahora si ingreso una ruta que si existe como controlador que tome como prioridad el controlador y no la accion x con el %username%

Se entiende?


Add this handler to your application bootstrap. And modify following forward path as you want

$eventsManager = new \Phalcon\Events\Manager();
$eventsManager->attach("dispatch", function($event, $dispatcher, $exception) use ($di) {
            if ($event->getType() == 'beforeException') {
                switch ($exception->getCode()) {
                    case \Phalcon\Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
                    case \Phalcon\Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
                        $dispatcher->forward(array(
                            'controller' => 'YOUR_CONTROLLER',
                            'action'     => 'YOUR_ACTION,
                            ....'
                        ));
                        return false;
                }
            }
        });

//Bind the EventsManager to the dispatcher
$dispatcher->setEventsManager($eventsManager);

$di->setShared('dispatcher', $dispatcher);