I'm writing my custom router for a Zend Framework 2 project extending Zend\Mvc\Router\RouteInterface. The routes should come from a database (large project with hundreds of pages). A working Router obviously only needs two methods: match()
and assemble()
. The match one I got working alright.
But what about assemble()
? What should this method return? Could it be it only returns the base path of the Application?
Here is what one of the internal routers (Zend\Mvc\Router\SimpleRouteStack) of ZF2 does:
/**
* assemble(): defined by RouteInterface interface.
*
* @see \Zend\Mvc\Router\RouteInterface::assemble()
* @param array $params
* @param array $options
* @return mixed
* @throws Exception\InvalidArgumentException
* @throws Exception\RuntimeException
*/
public function assemble(array $params = array(), array $options = array())
{
if (!isset($options['name'])) {
throw new Exception\InvalidArgumentException('Missing "name" option');
}
$route = $this->routes->get($options['name']);
if (!$route) {
throw new Exception\RuntimeException(sprintf('Route with name "%s" not found', $options['name']));
}
unset($options['name']);
return $route->assemble(array_merge($this->defaultParams, $params), $options);
}
Reference: Custom Routing in Zend Framework 2