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

Accessing default params

I have a route that looks like this:

        $router->add("/{uid:[0-9]+}/:params", "User::view");

In my controller, I want to be able to distinguish between the case where the user arrives at the page via https://example.com/1234/ and https://example.com/1234/ABC.

I'm trying to do this by checking $this->dispatcher->getParams(), but getParams() only seems to give me the uid and not any additional parameters passed. What am I doing wrong?

Thanks so much!



4.0k
Accepted
answer

Try change route to:

$router->add("/{uid:[0-9]+}/:params", array("controller" => "user", "action"=> "view", "params" => 2));

and check $this->dispatcher->getParams() output.



4.2k
edited Jun '15

Thanks Paulius!

What would my action definition look like? public function viewAction($uid) or public function viewAction()?



4.2k

Seems like in this case it wouldn't pass any parameters to the action and I'd have to get uid via $this->dispatcher->getParams() too.

Also, I was making a mistake capitalzing the first letter of the controller name. Looks like you need to do that in the shorthand notation but not in the full notation. So confusing!

Thanks though. It works now!