How to get url parameters

Hi guys,

How can I get id value in this URL example

http://localhost/phalcon-crud/index/update/id/3

the id value is 3 and i'm using a router

$router->add("/delete/id/:params", array( 'controller' => 'index', 'action' => 'delete', 'id' => 1, 'params' => 1 ));

to generate that URL, and also how can i access that value in a update controller

Many thanks,

I think it's something like this:

in router:

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

in Controller:

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


3.2k
edited Sep '15

this is like

      $router->add(
        "/index/update/([0-9]{2})/:params",
        array(
            "controller" => "index",
            "action"     => "update",
            "id"       => 1, // ([0-9]{4})
            rest of it..
      )

you dont need to have \id\ you can either remove it or getting it as first parameter and the value as second parameter

    $this->dispatcher->getParam("id");

https://docs.phalconphp.com/en/latest/reference/routing.html#parameters-with-names