XF 2.1 How do I format this template link?

grantus

Active member
I have my form action:

Code:
<xf:form action="{{ link('newbattle/cpanel/save', $newbattle) }}" upload="true" ajax="true" class="block">

My url is like this: newbattle/cpanel/r/24496/add. Since the form is linking to newbattle/cpanel/save it's not working. How should the link be formatted since I have a dynamic URL?

So I tried to test (I'm not sure how to format with the "/save" at the end either):

Code:
<xf:form action="{{ link('newbattle/cpanel/', null, {'r': $receiver_user_id}, $newbattle) }}" upload="true" ajax="true" class="block">

Which gives me the url like this: newbattle/cpanel/?r=24496 which doesn't work.

When I put the url directly into the link like this it works: newbattle/cpanel/r/24496/save
 
What are the parameters for the pertinent route? The array(-like) in the 2nd argument should correspond with them.
Just standard like this:

Code:
cpanel/r/:int<r>/

In my controller:

Code:
public function getParamUserId(ParameterBag $params) {
        $params_user_id = $params->r;
    
        return $params_user_id;
    }

Then I call $this->getParamUserId($params) where needed in my other methods.
 
Then {{ link('newbattle/cpanel/r/save', {'r': 123}) }} should work.

Then I call $this->getParamUserId($params) where needed in my other methods.
You can also just change the parameter name to int<user_id> and get it directly via $params->user_id, but I suppose that's a matter of preference.
 
Then {{ link('newbattle/cpanel/r/save', {'r': 123}) }} should work.


You can also just change the parameter name to int<user_id> and get it directly via $params->user_id, but I suppose that's a matter of preference.

This is what I was trying before:
Code:
{{ link('newbattle/cpanel/r/save', {'r': $receiver_user_id}, $newbattle)}}
but I was getting errors about $newbattle at the end.

So now:
Code:
{{ link('newbattle/cpanel/r/save', {'r': $receiver_user_id})}}
works great.

Thanks.
 
Top Bottom