Created
May 11, 2018 07:42
-
-
Save bwaidelich/b5ef25ae82cdbca524edc4fe5ef196ee to your computer and use it in GitHub Desktop.
Neos Flow routing "remaining URL segments"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- | |
uriPattern: '{@action}/{segments}.html' | |
defaults: | |
'@package': 'Some.Package' | |
'@controller': 'SomeController' | |
'@action': 'index' | |
'@format': 'html' | |
routeParts: | |
'segments': | |
handler: 'Some\Package\Routing\SegmentsRoutePart' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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