Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Neos Flow routing "remaining URL segments"
-
uriPattern: '{@action}/{segments}.html'
defaults:
'@package': 'Some.Package'
'@controller': 'SomeController'
'@action': 'index'
'@format': 'html'
routeParts:
'segments':
handler: 'Some\Package\Routing\SegmentsRoutePart'
<?php
namespace Some\Package\Routing;
use Neos\Flow\Mvc\Routing\Dto\MatchResult;
use Neos\Flow\Mvc\Routing\DynamicRoutePart;
/**
* Route Part that consumes all remaining URL segments and return them as array
*/
class SegmentsRoutePart extends DynamicRoutePart
{
protected function findValueToMatch($requestPath)
{
if (empty($this->splitString)) {
return $requestPath;
}
// return the whole remaining $requestPath until the last occurrence of the next static part (i.e. ".html")
return substr($requestPath, 0, strripos($requestPath, $this->splitString));
}
protected function matchValue($value)
{
return new MatchResult(explode('/', $value));
}
protected function resolveValue($value)
{
if (is_array($value)) {
$value = implode('/', $value);
}
return parent::resolveValue($value);
}
}
<?php
namespace Some\Package\Controller;
use Neos\Flow\Mvc\Controller\ActionController;
class SomeController extends ActionController
{
/**
* @param array $segments
* @return string
*/
public function indexAction(array $segments)
{
// ...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.