Skip to content

Instantly share code, notes, and snippets.

@bwaidelich
Created May 11, 2018 07:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bwaidelich/b5ef25ae82cdbca524edc4fe5ef196ee to your computer and use it in GitHub Desktop.
Save bwaidelich/b5ef25ae82cdbca524edc4fe5ef196ee to your computer and use it in GitHub Desktop.
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