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.

Help ! I want to get the uri segment in the volt.

The url is like this : http://www.abc.com/user/profile/5

how could i get the '5'?

i looked up something about this in the documentation, i can't get the answer in the end.

that's all , my english is poor. thank you!!



31.3k

Hi,

are you using a micro app or a full stack mvc ?

"5" will be passed to your action as the first argument. Your controller action needs to set that value in the view, as a variable (for example, user_id). You can then access "5" in Volt by accessing user_id. For example, {{ user_id }}.



7.6k
Accepted
answer

There are many ways to access URL parameters in view but the best practice is that you should get it from dispatcher and pass it to view via controller/action

a basic example:

// URL : http://www.abc.com/user/profile/5

// in action
$this->view->user_id = $this->dispatcher->getParams()[0];
// in view
{{ user_id }}

Or directly in volt file

{% var params = dispatcher.getParams() %}
{{ params[0] }}

i solved my question. Thanks all!

thank you very much

"5" will be passed to your action as the first argument. Your controller action needs to set that value in the view, as a variable (for example, user_id). You can then access "5" in Volt by accessing user_id. For example, {{ user_id }}.

i just write this for pratising,bro.

Hi,

are you using a micro app or a full stack mvc ?