Building Links with an extended MajorRoute?

Jaxel

Well-known member
I'm using the following code for my media library:
Code:
<?php

class EWRmedio_Route_Media implements XenForo_Route_Interface
{
	public function match($routePath, Zend_Controller_Request_Http $request, XenForo_Router $router)
	{
		return $router->getRouteMatch('EWRmedio_ControllerPublic_Media', 'index', 'media', $routePath);
	}

	public function buildLink($originalPrefix, $outputPrefix, $action, $extension, $data, array &$extraParams)
	{
		return XenForo_Link::buildBasicLinkWithIntegerParam($outputPrefix, $action, $extension, $data, 'media_id', 'media_title');
	}
}
Using that code works great... i can create links as follows:
{xen:link 'full:media', $media} would return xenforo/media/{$media_title}.{$media_id}

However, now I want to create links as follows: /media/category/{$category_title}.{$category_id}

How would I construct the buildLink function for this? and how would I call it?
 
I solved it...

First I created a route prefix called "media_category"... it points to "EWRmedio_Route_Category"
Code:
<?php

class EWRmedio_Route_Category implements XenForo_Route_Interface
{
	public function match($routePath, Zend_Controller_Request_Http $request, XenForo_Router $router)
	{
		return $router->getRouteMatch('EWRmedio_ControllerPublic_Media', 'index', 'media_category', $routePath);
	}

	public function buildLink($originalPrefix, $outputPrefix, $action, $extension, $data, array &$extraParams)
	{
		$outputPrefix = str_replace('_', '/', $outputPrefix);
		return XenForo_Link::buildBasicLinkWithIntegerParam($outputPrefix, $action, $extension, $data, 'category_id', 'category_name');
	}
}

In the buildLink function, I do a simple str_replace to replace any instance of _ with /

Then I simply call the function in templates as: {xen:link 'full:media_category', $category}

Simple and elegant...
 
Top Bottom