We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

How to get URL of current page


Is there a way in Volt (or even in the controller I guess if necessary) to get the URL of the current page? I need a URL for my form to submit to (and I'm loathe to use the helpers), and would rather not have to enter the full URL manually.

Honestly I know it's not much work, but I'm learning Phalcon as I go and want to learn any shortcuts I can.

It seems it should be $this->dispatcher-> getControllerName() . $this->dispatcher-> getActionName() (of course if were added 'dispatcher' to DI container) Btw, if you won't present url for your form, it should submit itself to the same url from where it was loaded.

But then I have to deal with any parameters I might need. Honestly if that's the only way to do it, I'd much rather just hardcode the page URL and use template variables transferred in from the controller, for parameters.

Leaving the "action" attribute blank will work, but is against HTML5 standards.

In this case it seems there is not 'easy' solution here. You may also implementing saving current url every time dispatcher works using event manager and saving current url to variable.

edited Jul '14

Hi, you can use this in volt:

{{ router.getRewriteUri() }}

Thanks ~chebureque - that was it exactly!


@quasipickle glad I could help you! Just curiosity - for what do you need current page url in your form to submit it?

@chebureque - the form's "action" attribute requires a URL. Leaving it blank isn't up to standard.