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

can i change router object in micro app ?

i am using micro app( \Phalcon\Mvc\Micro ).

i would like to change the internal router of this.

namespace PhalconRest\Router;
class BaseRouter extends \Phalcon\Mvc\Router\Group
{
}

class products extends BaseRouter {
    public function Initialize() {
        $this->add('/products',
            array(
                'action' => 'index'
            )
        );
    }
}

class Router extends \Phalcon\Mvc\Router
{
    public function __construct()
    {
        $this->Initialize();
    }

    public function Initialize()
    {
        $this->LoadRouteGroup();

        $this->notFound(array(
            "controller" => "products",
            "action" => "index"
        ));

        $this->handle();
    }

    private function LoadRouteGroup()
    {
        $this->mount( new products());
    }
}

[bootstrap]
/**
 * Registering a router In Service Section
 */
$di->setShared('router', function() use ($di) {
    $router = new PhalconRest\Router\Router( false);

    return $router;
});

class Application extends \Phalcon\Mvc\Micro {
    public function main()
    {
        blah blah~~
        /*
        * Load Service Section
        */
        $this->setDI( $di);
        $this->handle();
    }
}

$app = new Application();
$app->main();

Router is not working properly. Are there anything that i can change?

any advice?



43.9k

Hi,

maybe with some error messages we could be more helpfull ...