Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

How to get URL of current page

Hi,

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.



10.7k
Accepted
answer
edited Jul '14

Hi, you can use this in volt:

{{ router.getRewriteUri() }}

Thanks ~chebureque - that was it exactly!



10.7k

@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.