XF 2.0 buildLink route parameter

CMTV

Well-known member
Hi!

I have a custom route called google-search with "Route format" set to :str<search_query>/.

Now I want to redirect to my google-search page with search_query specified:

PHP:
return $this->redirect($this->buildLink('google-search', "My Search Query"));

But for some reason it always redirects me to /index.php?google-search/ when it should redirect to /index.php?google-search/My Search Query/.

What am I doing wrong?
 
Ok. Solved my problem. There might be more than one route parameter so I simply need to put $searchQuery string inside an array:
PHP:
return $this->redirect($this->buildLink('google-search', ['search_query' => 'My Search Query']));
 
I'm actually stuck with the same thing, just in the template part. I have two ids, id1 and id2, and I need both of them for link building.
I've looked into threads/post:
<a href="{{ link('threads/post', $thread, {'post_id': $post.post_id}) }}"
->
<xf:button href="{{link('custom/action', $custom, {'id2' : $id2}) }}"
results in
/custom/action/?user_id=<id2>

<xf:button href="{{link('custom/action', {'id1' : $id1, 'id2' : $id2}) }}"
Results in
/custom/action/<id2>

So $id1 is completely dropped. $id1 is the key of $custom.
Anyone any idea?
 
:int<id1,id2>/.

That format is not actually meant for multiple important input parameters, but allows you to have the title in the URL. For example :int<thread_id,title> results in the format buildlink-route-parameter.153119. If you have multiple parameters that are important, you need to split them up (:int<id1>/:int<id2>).
 
It was actually just another simple thing - the variable was not at all in the template due to a typo in the macro call.
 
You need to specify both your ids in "Route format" of your "custom/action". For exapmle: :int<id1,id2>/.
That format is not actually meant for multiple important input parameters, but allows you to have the title in the URL. For example :int<thread_id,title> results in the format buildlink-route-parameter.153119.
Actually, I needed that, and it hit me hard when I realized that title is a hardcoded reference. So obviously id2 did not work - my route was :int<id1, id2>. Thank you for the hints.
 
Top Bottom