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

Creacion route

Hola Necesito crear los routers desde los controladores,


     class BaseController extends Phalcon\Mvc\Controller {
        protected function registerController(){
            $router = new Phalcon\Mvc\Router();

            $router->add(
                "/",
                array(
                        "controller" => "index",
                        "action"     => "get"));
        }
    }

  class IndexController extends BaseController{
        public function Initialize(){
            $this->registerController(); 
        }

        public function getAction(){
            echo "entroooooooooo";
        }
    }

Gracias

It won't work. You have to define your routes in bootstrap before use them.

$di['router']=function() {
   $router = new Phalcon\Mvc\Router();
   $router->add(
                "/",
                array(
                        "controller" => "index",
                        "action"     => "get")
    );
    return $router;
}

If you have to define routes in controllers you have to use Annotations Router. https://docs.phalcon.io/en/latest/reference/routing.html#annotations-router