Guillaume
Guillaume

Reputation: 13

Phalcon PhpFramework - Routing

Have an application using phalcon and I wants routes URLs like this :

http://localhost/my-website/admin/cat -> use the "cat" controller and not the "admin" controller

Have done this and its works

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

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

but how to route things like :

http://localhost/my-website/admin/cat/updatecat/22 -> use the "cat" controller with action "updatecat" and parameter "22" and not the "admin" controller

Upvotes: 0

Views: 102

Answers (1)

Scriptonomy
Scriptonomy

Reputation: 4055

Phalcon PHP custom route

This is how you do a custom route like yours:

$router->add(
"/admin/cat/([0-9]+)",
array(
    "controller" => "cat",
    "action"     => "index",
    "id"     => 1
));

You pickup the param in the controller like this:

$id = $this->dispatcher->getParam('id');

Upvotes: 2

Related Questions