eZ\Publish\Core\MVC\Symfony\Routing\Generator\RouteReferenceGenerator::generate PHP Метод

generate() публичный Метод

If $resource is null, generated route reference will be based on current request's route and parameters.
public generate ( mixed $resource = null, array $params = [] ) : RouteReference
$resource mixed The route name. Can be any resource supported by the different routers (e.g. Location object).
$params array Array of parameters, used to generate the final link along with $resource.
Результат eZ\Publish\Core\MVC\Symfony\Routing\RouteReference
    public function generate($resource = null, array $params = array())
    {
        $request = $this->getCurrentRequest();
        if ($resource === null) {
            $resource = $request->attributes->get('_route');
            $params += $request->attributes->get('_route_params', array());
        }
        $event = new RouteReferenceGenerationEvent(new RouteReference($resource, $params), $request);
        $this->dispatcher->dispatch(MVCEvents::ROUTE_REFERENCE_GENERATION, $event);
        return $event->getRouteReference();
    }

Usage Example

 /**
  * Used by the REST API to reference downloadable files.
  * It redirects (permanently) to the standard ez_content_download route, based on the language of the field
  * passed as an argument, using the language switcher.
  *
  * @param mixed $contentId
  * @param int $fieldId
  * @param \Symfony\Component\HttpFoundation\Request $request
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function redirectToContentDownloadAction($contentId, $fieldId, Request $request)
 {
     $content = $this->contentService->loadContent($contentId);
     $field = $this->findFieldInContent($fieldId, $content);
     $params = array('content' => $content, 'fieldIdentifier' => $field->fieldDefIdentifier, 'language' => $field->languageCode);
     if ($request->query->has('version')) {
         $params['version'] = $request->query->get('version');
     }
     $downloadUrl = $this->router->generate($this->routeReferenceGenerator->generate('ez_content_download', $params));
     return new RedirectResponse($downloadUrl, 301);
 }
All Usage Examples Of eZ\Publish\Core\MVC\Symfony\Routing\Generator\RouteReferenceGenerator::generate
RouteReferenceGenerator