TheBigK
Well-known member
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
2. Created a Controller:
Events/ControllerPublic/Event.php
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!
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!