Rasmus Vind
Well-known member
I'm in the process of writing an add-on which will have non-discoverable links to entities. To stay compatible with the same add-on for XF1, the link looks something like this:
The ID of an entity is a 32 character hash.
I did the following in my route:
But this means that all my actions in the controller stop working. Is there a way to define something like this:
to say that it is only an item ID if it is 32 characters long.
Otherwise I see no other way to do this than this:
But it feels a bit like a hack. In XF1 I had a way to actually make my own logic in the
Is there a similar way to do this in XF2?
Thanks for your time.
Code:
index.php?pastebin/0123456789abcd23213112abcd123412/
I did the following in my route:
Code:
:str<paste_id>
Code:
:str<paste_id>{32}
Otherwise I see no other way to do this than this:
PHP:
<?php
namespace VindIT\Pastebin\Pub\Controller;
class MyController extends \XF\Pub\Controller\AbstractController
{
public function actionIndex(\XF\Mvc\ParameterBag $params)
{
if ($params->paste_id == 'my-action')
{
return $this->rerouteController(__CLASS__, $params->paste_id, $params);
}
return $this->message('View entity: ' . $params->paste_id);
}
public function actionMyAction(\XF\Mvc\ParameterBag $params)
{
return $this->message('My action');
}
}
Route_Prefix
class:
PHP:
<?php
class Rapbin_Route_Prefix_Pastebin implements XenForo_Route_Interface
{
public function match($routePath, Zend_Controller_Request_Http $request, XenForo_Router $router)
{
$action = $router->resolveActionWithStringParam($routePath, $request, 'paste_id');
$pasteId = $request->getParam('paste_id');
if ($pasteId)
{
$normalId = $this->_getPasteModel()->readObfuscatedId($pasteId);
$request->setParam('paste_id', $normalId);
}
return $router->getRouteMatch('Rapbin_ControllerPublic_Pastebin', $action, 'pastebin');
}
public function buildLink($originalPrefix, $outputPrefix, $action, $extension, $data, array &$extraParams)
{
if (! empty($data['paste_id']))
{
$data['paste_id'] = $this->_getPasteModel()->makeObfuscatedId($data['paste_id']);
}
return XenForo_Link::buildBasicLinkWithStringParam($outputPrefix, $action, $extension, $data, 'paste_id');
}
protected function _getPasteModel()
{
return XenForo_Model::create('Rapbin_Model_Paste');
}
}
Thanks for your time.