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

Getting "anonymous" parameters without routing

Hey all,

I have a url in my app which goes https://app.com/users/add/abcdefg/123456

What's the best way of getting the "abcdefg" and "123456" parameters ? Without explode()'ing the URL, clearly

Thanks Shai



98.9k

Aren't you using Phalcon\Mvc\Router?

I'm using the default behavior. If I understood correctly there's a default behavior with which I wouldn't have to define routes using a custom Router.

The docs aren't really specific about that and the information about Router shows how to use the class but not where to actually use it.. which makes it a bit tricky. I would rather not use it for this specific situation but if its an easier option, I can ...



98.9k
edited Oct '14

OK, I misunderstood because the title says "Getting "anonymous" parameters without routing", I assume default routes is also routing, but nevermind

You just have to receive those parameters in the action:

public function addAction($param1, $param2)
{
    $param1; // abcdefg
    $param2; // 123456
}

Hah. easy and smooth. Would be cool to find this in the docs ... I couldn't find it when looking in the Routing docs.

Thank you very much :) Shai



1.6k
edited Oct '14
<?php

$this->dispatcher->getParam(0);
$this->dispatcher->getParam(1);

//or use getParams() to get all parameters in array