public render ( string $action, array $arguments = [], string $controller = null, string $package = null, string $subpackage = null, string $section = '', string $format = '', array $additionalParams = [], boolean $addQueryString = false, array $argumentsToBeExcludedFromQueryString = [], boolean $useParentRequest = false, boolean $absolute = true, boolean $useMainRequest = false ) : string | ||
$action | string | Target action |
$arguments | array | Arguments |
$controller | string | Target controller. If NULL current controllerName is used |
$package | string | Target package. if NULL current package is used |
$subpackage | string | Target subpackage. if NULL current subpackage is used |
$section | string | The anchor to be added to the URI |
$format | string | The requested format, e.g. ".html" |
$additionalParams | array | additional query parameters that won't be prefixed like $arguments (overrule $arguments) |
$addQueryString | boolean | If set, the current query parameters will be kept in the URI |
$argumentsToBeExcludedFromQueryString | array | arguments to be removed from the URI. Only active if $addQueryString = TRUE |
$useParentRequest | boolean | If set, the parent Request will be used instead of the current one. Note: using this argument can be a sign of undesired tight coupling, use with care |
$absolute | boolean | By default this ViewHelper renders links with absolute URIs. If this is FALSE, a relative URI is created instead |
$useMainRequest | boolean | If set, the main Request will be used instead of the current one. Note: using this argument can be a sign of undesired tight coupling, use with care |
return | string | The rendered link |
public function render($action, $arguments = array(), $controller = null, $package = null, $subpackage = null, $section = '', $format = '', array $additionalParams = array(), $addQueryString = false, array $argumentsToBeExcludedFromQueryString = array(), $useParentRequest = false, $absolute = true, $useMainRequest = false)
{
$uriBuilder = $this->controllerContext->getUriBuilder();
if ($useParentRequest) {
$request = $this->controllerContext->getRequest();
if ($request->isMainRequest()) {
throw new ViewHelper\Exception('You can\'t use the parent Request, you are already in the MainRequest.', 1360163536);
}
$uriBuilder = clone $uriBuilder;
$uriBuilder->setRequest($request->getParentRequest());
} elseif ($useMainRequest === true) {
$request = $this->controllerContext->getRequest();
if (!$request->isMainRequest()) {
$uriBuilder = clone $uriBuilder;
$uriBuilder->setRequest($request->getMainRequest());
}
}
$uriBuilder->reset()->setSection($section)->setCreateAbsoluteUri($absolute)->setArguments($additionalParams)->setAddQueryString($addQueryString)->setArgumentsToBeExcludedFromQueryString($argumentsToBeExcludedFromQueryString)->setFormat($format);
try {
$uri = $uriBuilder->uriFor($action, $arguments, $controller, $package, $subpackage);
} catch (\Exception $exception) {
throw new ViewHelper\Exception($exception->getMessage(), $exception->getCode(), $exception);
}
$this->tag->addAttribute('href', $uri);
$this->tag->setContent($this->renderChildren());
$this->tag->forceClosingTag(true);
return $this->tag->render();
}