• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

How to build a link using text input?

TheBigK

Well-known member
#1
I'm trying to understand how XenForo builds URLs based on the input provided (for example, thread title). I have created a simple text input box that will accept a string and then use that string to build a route that will display a text message.

Note, this is my preparation for a simple 'events' plugin I'm building.

So far I've done the following:-

1. Defined route 'events' in the XenForo's 'Create Route Prefix' in adminCP.
Here's the corresponding code:
Events/Route/Public/Event.php
PHP:
<?php
class Events_Route_Public_Event implements XenForo_Route_Interface
{
public function match($routePath, Zend_Controller_Request_Http $request, XenForo_Router $router)
{
return $router->getRouteMatch('Events_ControllerPublic_Event', $routePath);
}
}
2. Created a Controller:
Events/ControllerPublic/Event.php
PHP:
<?php
class Events_ControllerPublic_Event extends XenForo_ControllerPublic_Abstract
{
public function actionIndex()
{
//This will build the Add New Event Page on /events/add/
$viewParams = array();
return $this->responseView('Events_ViewPublic_Event', 'events_add_new', $viewParams);
}

public function actionAdd()
{
//Get information from user input
$eventTitle = $this->_input->filterSingle('event_name', XenForo_Input::STRING);
//Create DataWriter
$dw = XenForo_DataWriter::create('Events_DataWriter_Index');
$dw->set('event_title', $eventTitle);
$dw->save();

return $this->responseRedirect Or What?

// Question: What do I return here? Response Redirect Or Response View?
);
}

}
My data-writer saves the input string to the database assuming that I'll need to save it. My question is, what would be my next step?

The desired result I want to achieve it this:

1. User enters Event Name: "Apple iPhone Launch Event"
2. I want to build a page: localhost/xf/events/apple-iphone-launch-event.1/ (where the last digit would be the event ID).

Will really appreciate your responses. Thanks!
 

TheBigK

Well-known member
#3
Have a look at the XenForo/Route/Prefix/Forums.php buildLink-Method.
Well, I did look at that function. I began reading XenForo_ControllerPublic_Forum's actionAddThread(). It uses buildlink method, which I suppose is the one that you suggested.

Reading the builLink method alone is confusing. Is there any existing tutorial that I can refer to to understand what's really going on?
 

TheBigK

Well-known member
#4
I guess I've made some progress. But I'm still stuck at understanding what the '$data' part in the buildLink function:

PHP:
public static function buildPublicLink($type, $data = null, array $extraParams = array(), $skipPrepend = false)
The description says "@Param mixed $data Data that the prefix/action should be applied to, if applicable"; but I'm not getting what it means and what should I really pass as $data.
 
#5
Did you ever figure this out?

I'm trying to have my code redirect to a thread that is created in the post method.

So:

PHP:
return $this->responseRedirect(
    XenForo_ControllerResponse_Redirect::SUCCESS,
    XenForo_Link::buildBasicLink('threads/', $threadID),
    new XenForo_Phrase('application_received')
);