简体   繁体   中英

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

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');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM