我正在为一个扩展为Zend\Mvc\Router\RouteInterface的Zend Framework 2项目编写我的自定义路由器。路线应该来自数据库(大型项目有数百页)。工作路由器显然只需要两种方法:match()
和assemble()
。我工作的比赛一切正常。ZF2中Zend Mvc Router RouteInterface :: assemble()的输出是什么
但是assemble()
呢? 该方法返回什么?难道它只是返回应用程序的基本路径?
这里是内部路由器的什么人(Zend\Mvc\Router\SimpleRouteStack)ZF2的作用:
/**
* 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);
}
参考:Custom Routing in Zend Framework 2