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

How can I pass two or more parameters by routing annotations?

I have to pass two parameters in the routing annotations, but I get 404 not found

and I don't know why?

<?php
/**
*@RoutePrefix("/Product")
*/
class ProductController extends BaseController
{
 /**
 * @Get("/select/{serial:[a-z0-9]}/{id:[0-9]}")
 */
public function selectAction($serial,$id){
...
}
}

and the path that appears in the browser is:

sipv/product?serial=aad123&id=12

the correct path is

sipv/product/aad123/12

but i don't know for configure the route

edited Jun '15

https://docs.phalcon.io/en/latest/reference/routing.html#parameters-with-names

$router->add(
    "/product/select/{serial:[a-zA-Z0-9_]+}/{id:[0-9]+}",
    array(
        "controller" => "product",
        "action"     => "select"
    )
);

Or getParam

$router->add(
    "/product/([a-zA-Z0-9_]+)/([0-9]+)",
    array(
        "controller" => "product",
        "action"     => "select",
        "serial"       => 1, 
        "id"      => 2
    )
);

Or

$router->add(
    "/product/select/([a-zA-Z0-9_]+)/([0-9]+)",
    array(
        "controller" => "product",
        "action"     => "select",
        "serial"       => 1, 
        "id"      => 2
    )
);

Or 

.... More

When your url looks as follows,

    sipv/product/param = 12

add route,

          $router->add(
    '/sipv/product/:params',
    array(
        'module'     => 'module-name',
        'controller' => 'index',
        'action'     => 'action-name',
        'param'     =>1,
    )
    );

Then in your action

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

Your can go to the following link to read in depth

  https://docs.phalcon.io/en/latest/reference/routing.html


5.7k

Using annotations, have you tried updating your regular expressions by appending each with a "+" to specify one or more?

You Currently have:

<?php
/**
*@RoutePrefix("/Product")
*/
class ProductController extends BaseController
{
 /**
 * @Get("/select/{serial:[a-z0-9]}/{id:[0-9]}")
 */
public function selectAction($serial,$id){
...
}
}

What happens if you update it like so?

<?php
/**
*@RoutePrefix("/Product")
*/
class ProductController extends BaseController
{
 /**
 * @Get("/select/{serial:[a-z0-9]+}/{id:[0-9]+}")
 */
public function selectAction($serial,$id){
...
}
}

Notice that I updated Get("/select/{serial:[a-z0-9]+}/{id:[0-9]+}") to include the "+" after each regex



17.7k

why the browser displays the route as well?

sipv/product?serial=aad123&id=12

I put the path manually and can access but I'm sending data via get and appears this route



5.7k

What web server are you running? Nginx, Apache, etc..?

why the browser displays the route as well?

sipv/product?serial=aad123&id=12

I put the path manually and can access but I'm sending data via get and appears this route