php-mvc
php-mvc copied to clipboard
Issue with action parameters
Hello thank you for your awesome framework. However I am at loss on how to add parameters after the action. What I wish to accomplish is this:
/controller/action/id such example as /contacts/index/5 to read contact with id 5
Every iteration i do gives error on Router.php I have added this $router->add('{controller}/{action}/{id:\d+}'); to the routes but not doing anything.
Do you get an error when you use that route? If so, what does it say?
That route looks fine - if you have that route, with the URL /contacts/index/5, the framework will run the indexAction method in the Contacts controller. The ID from the route will be available in the route_params property of the current controller, e.g.
public function indexAction()
{
$id = $this->route_params['id'];
}