Creating Sub Pages within a Mod?

Jaxel

Well-known member
Okay, previously I created a mod active at:
http://xen1.8wayrun.com/portal/

I would now like to make sub pages:
http://xen1.8wayrun.com/portal/lorem
http://xen1.8wayrun.com/portal/ipsum
http://xen1.8wayrun.com/portal/dolor

Basically, I will have a database table of subpages (this will be a lite CMS) where the name of the page will be the unique key (if a numeric node id is required, then thats okay too). So when someone goes to /portal/lorem, it will extract the word "lorem" and search the database for the matching result; then display it. Since there will be many pages, and all with different names, its not feasible to create an action for each and every page. So I want the actions created dynamically, the same way thread and member page actions are created.

How would something like this be accomplished?
 
Within the Index.php file of your portal you will create a new function like so:
PHP:
public funtion actionLorem {
// code goes here
}

Then you can access it via the address above using /lorem/
 
Steve... I already said in my original post that defined functions would not be feasible.

If I release this mod to the public, administrators will be able to name their pages anything they want... and I don't expect them to what to have to define a function for each and every page.
 
You would have to do a foreach in the page to display but you would still need to use an action controller to view the page no matter what. So you would need to do something like: portal/page?lorem/

That is the only feasible way I can think to go about it.
 
Good point, open up: library/XenForo/ControllerPublic/User.php

Look through there for the proper way to do just that.
 
Good point, open up: library/XenForo/ControllerPublic/User.php

Look through there for the proper way to do just that.
You mean library/XenForo/ControllerPublic/Member.php

And I've been looking through it, and I can't get anything working...

My route prefix looks like this:
Code:
<?php

class EWRporta_Route_Prefix_Portal implements XenForo_Route_Interface
{
	public function match($routePath, Zend_Controller_Request_Http $request, XenForo_Router $router)
	{
		$action = $router->resolveActionWithStringParam($routePath, $request, 'pageName');
		return $router->getRouteMatch('EWRporta_ControllerPublic_Portal', $action, 'EWRporta');
	}
}

I figured it would be as simple as putting this at the beginning of my index to retrieve the data, but I cant get it working:
Code:
$pageName = $this->_input->filterSingle('pageName', XenForo_Input::STRING);
 
I'm not sure if this is the best way but it worked:

Go to AdminCP > Development > Route Prefixes. Add a new one for you (let's say "portal", and configure it to use your class)
In your route prefix class, put something like this

PHP:
class MyAddon_RoutePrefix implements XenForo_Route_Interface {
	public function match($routePath, Zend_Controller_Request_Http $request, XenForo_Router $router) {
		$page = $routePath; // it will be lorem/ipsum/dolor/blah blah
		return $router->getRouteMatch('MyAddon_Controller','open',$page);
	}

	public function buildLink($originalPrefix, $outputPrefix, $action, $extension, $data, array &$extraParams) {
		// do something interesting here if you want
	}
}

And use this in your controller
PHP:
$page = $this->_routeMatch->getMajorSection();

A little bit over complicated :(
 
Top Bottom