Dynamic routes

Hello,

I'm new to Phalcon an I'm trying to archive a route schema like a short url service where / goes to indexAction() and /hjK8uj or /uIUn7y goes to showAction(), both in indexController.

Note that I have other actions like /save or /help.

I have a small Flask (python) app and I can archive this like:

@app.route('/')
@app.route('/<slug>')
def index(slug=None):
    if slug:
        get the view for the slug
    else:
        get the view for the home page

Thanks

Nuno



2.3k

Hi,

Just found out how can I do this. Create a new route just like the one bellow and to catch all /xpto url's The only thing I would like to do is not declare all other routes like save or help, but I think it's not possible.

<?php

$router = new \Phalcon\Mvc\Router();

$router->add("/:controller", array(
    'controller'  => 'index',
    'action'      => 'show',
    'slug'            => 1,

));

return $router;