php-mvc icon indicating copy to clipboard operation
php-mvc copied to clipboard

Issue with action parameters

Open Dripnix opened this issue 5 years ago • 1 comments

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.

Dripnix avatar Jun 10 '20 08:06 Dripnix

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'];
}

daveh avatar Jun 10 '20 14:06 daveh