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 to Rewrite URL in phalcon

how to Rewrite URL in phalcon. example : https://localhost/cms-framework-php/1/product I want Rewrite https://localhost/cms-framework-php/product thansk you!



6.0k
Accepted
answer

Hi there, Can I ask what's the point of doing this routing? The value "1" is an ID of product?

yes '1' is an product

router $route = $router->add( "/{id}/([a-zA-Z0-9_-]+)", [ 'namespace' => 'MyApp\Controllers', "controller" => "product", "action" => "index", "id" => 1, "title" => 2, ] );

In my logic you can have '/1/product' and than you can use the parameter '1' in Controller

OR

'/product' but you have no access to this param.

How do you plan to read the product's ID from this url: https://localhost/cms-framework-php/product or are you going to query the database to retrieve the ID based on the product's name?