XF 2.1 [SOLVED]How to build link while creating a post in a thread?

asprin

Active member
As part of my addon, I'm creating a thread with the following code:
PHP:
$forum = \XF::app()->find( 'XF:Forum', $forum_id );
$user  = \XF::app()->find('XF:User', $user_id);
$title = 'Some title';
$message .= "\n\nYou can click [URL='".$this->buildLink('fc/view', $event)."']here[/URL] to view the event.";

This is not creating a link, rather just textual "here".
1580977771702.png


The expected link to be generated in this format:
index.php?fc/view/some-title-goes-here.16/

I've set up a route for this from ACP and it works fine when used with the link('fc/view/', $event) function inside the templates.

So, is there a way I could get the generated href value from the buildLink() function to be used inside the bbcode?
 

asprin

Active member
Ok, sovled it.

Used the full key as follows:
PHP:
\XF::app()->router('public')->buildLink('full:fc/view', $event);
 

TickTackk

Well-known member
Instead of building https://example.com/fc/view/<event title>.<event id>/ you build fs/view/<event title>.<event id>/ and so when you change the board URL or start using route filters, links don't break :D
 
Last edited:

Liam W

in memoriam 1998-2020
Instead of building https://example.com/fc/view/<event title>.<event id>/ you build fs/view/<event title>.<event id>/ and so when you change the board URL or start using route filters, links don't break :D

That won't work in this case. The BBCode renderer doesn't allow URL tags without a full URL.
 
Top