class Controller implements ContainerAwareInterface (View source)

Base controller.

Properties

protected Container|null $container

Methods

Request
getRequest()

Shortcut to return the request service.

setContainer(Container $container)

Sets the Container associated with this Controller.

Container
getContainer()

No description

mixed
getService(string|null $key = null) deprecated

Get mixed object from Dependency Injection container.

mixed
get(string $serviceName)

Return a service from container.

bool
has(string $serviceName)

Returns true if the service is defined.

AuthorizationChecker
getAuthorizationChecker()

Alias for $this->container['securityAuthorizationChecker'].

TokenStorageInterface
getTokenStorage()

Alias for $this->container['securityTokenStorage'].

EntityManager
em()

Alias for $this->container['em'].

Translator
getTranslator()

No description

Twig_Environment
getTwig()

No description

string
generateUrl(string|NodesSources $route, mixed $parameters = [], int $referenceType = Router::ABSOLUTE_PATH)

Wrap $this->container['urlGenerator']->generate

RedirectResponse
redirect(string $url, integer $status = Response::HTTP_FOUND)

Returns a RedirectResponse to the given URL.

static string
getCalledClass()

No description

validateAccessForRole(string $role)

Validate a request against a given ROLE_* and throws an AccessDeniedException exception.

RedirectResponse
removeTrailingSlashAction(Request $request)

Custom route for redirecting routes with a trailing slash.

bindLocaleFromRoute(Request $request, string $_locale = null)

Make translation variable with the good localization.

string
renderView(string $view, array $parameters = [])

Returns a rendered view.

Response
render(string $view, array $parameters = [], Response $response = null, string $namespace = "")

Return a Response from a template string with its rendering assignation.

JsonResponse
renderJson(array $data = [], int $httpStatus = JsonResponse::HTTP_OK)

No description

Response
forward(string $controller, array $path = [], array $query = [])

Forwards the request to another controller.

NotFoundHttpException
createNotFoundException(string $message = 'Not Found', Exception $previous = null)

Returns a NotFoundHttpException.

AccessDeniedException
createAccessDeniedException(string $message = 'Access Denied', Exception $previous = null)

Returns an AccessDeniedException.

Form
createForm(string|FormTypeInterface $type, mixed $data = null, array $options = [])

Creates and returns a Form instance from the type of the form.

FormBuilder
createFormBuilder(mixed $data = null, array $options = [])

Creates and returns a form builder instance.

createEntityListManager(mixed $entity, array $criteria = [], array $ordering = [])

Creates and returns an EntityListManager instance.

createContactFormManager()

Create and return a ContactFormManager to build and send contact form by email.

createEmailManager()

Create and return a EmailManager to build and send emails.

UserInterface|null
getUser()

Get a user from the tokenStorage.

bool
isGranted(mixed $attributes, mixed $object = null)

Checks if the attributes are granted against the current authentication token and optionally supplied object.

Details

Request getRequest()

Shortcut to return the request service.

Return Value

Request

ContainerAwareInterface setContainer(Container $container)

Sets the Container associated with this Controller.

Parameters

Container $container

Return Value

ContainerAwareInterface

Container getContainer()

Return Value

Container

mixed getService(string|null $key = null) deprecated

deprecated Use Controller::get to better match Symfony style.

Get mixed object from Dependency Injection container.

Alias for $this->container[$key]

Parameters

string|null $key

Return Value

mixed

mixed get(string $serviceName)

Return a service from container.

Parameters

string $serviceName

Return Value

mixed

bool has(string $serviceName)

Returns true if the service is defined.

Parameters

string $serviceName

Return Value

bool true if the service is defined, false otherwise

AuthorizationChecker getAuthorizationChecker()

Alias for $this->container['securityAuthorizationChecker'].

Return Value

AuthorizationChecker

TokenStorageInterface getTokenStorage()

Alias for $this->container['securityTokenStorage'].

Return Value

TokenStorageInterface

EntityManager em()

Alias for $this->container['em'].

Return Value

EntityManager

Translator getTranslator()

Return Value

Translator

Twig_Environment getTwig()

Return Value

Twig_Environment

string generateUrl(string|NodesSources $route, mixed $parameters = [], int $referenceType = Router::ABSOLUTE_PATH)

Wrap $this->container['urlGenerator']->generate

Parameters

string|NodesSources $route
mixed $parameters
int $referenceType

Return Value

string

RedirectResponse redirect(string $url, integer $status = Response::HTTP_FOUND)

Returns a RedirectResponse to the given URL.

Parameters

string $url
integer $status

Return Value

RedirectResponse

static string getCalledClass()

Return Value

string

validateAccessForRole(string $role)

Validate a request against a given ROLE_* and throws an AccessDeniedException exception.

Parameters

string $role

Exceptions

AccessDeniedException

RedirectResponse removeTrailingSlashAction(Request $request)

Custom route for redirecting routes with a trailing slash.

Parameters

Request $request

Return Value

RedirectResponse

protected Translation bindLocaleFromRoute(Request $request, string $_locale = null)

Make translation variable with the good localization.

Parameters

Request $request
string $_locale

Return Value

Translation

Exceptions

NoTranslationAvailableException

string renderView(string $view, array $parameters = [])

Returns a rendered view.

Parameters

string $view
array $parameters

Return Value

string

Response render(string $view, array $parameters = [], Response $response = null, string $namespace = "")

Return a Response from a template string with its rendering assignation.

Parameters

string $view Template file path
array $parameters Twig assignation array
Response $response Optional Response object to customize response parameters
string $namespace Twig loader namespace

Return Value

Response

Exceptions

Twig_Error_Runtime

See also

http://api.symfony.com/2.6/Symfony/Bundle/FrameworkBundle/Controller/Controller.html#method_render

JsonResponse renderJson(array $data = [], int $httpStatus = JsonResponse::HTTP_OK)

Parameters

array $data
int $httpStatus

Return Value

JsonResponse

protected Response forward(string $controller, array $path = [], array $query = [])

Forwards the request to another controller.

Parameters

string $controller The controller name (a string like BlogBundle:Post:index)
array $path An array of path parameters
array $query An array of query parameters

Return Value

Response A Response instance

protected NotFoundHttpException createNotFoundException(string $message = 'Not Found', Exception $previous = null)

Returns a NotFoundHttpException.

This will result in a 404 response code. Usage example:

throw $this->createNotFoundException('Page not found!');

Parameters

string $message A message
Exception $previous The previous exception

Return Value

NotFoundHttpException

protected AccessDeniedException createAccessDeniedException(string $message = 'Access Denied', Exception $previous = null)

Returns an AccessDeniedException.

This will result in a 403 response code. Usage example:

throw $this->createAccessDeniedException('Unable to access this page!');

Parameters

string $message A message
Exception $previous The previous exception

Return Value

AccessDeniedException

protected Form createForm(string|FormTypeInterface $type, mixed $data = null, array $options = [])

Creates and returns a Form instance from the type of the form.

Parameters

string|FormTypeInterface $type The built type of the form
mixed $data The initial data for the form
array $options Options for the form

Return Value

Form

protected FormBuilder createFormBuilder(mixed $data = null, array $options = [])

Creates and returns a form builder instance.

Parameters

mixed $data The initial data for the form
array $options Options for the form

Return Value

FormBuilder

EntityListManager createEntityListManager(mixed $entity, array $criteria = [], array $ordering = [])

Creates and returns an EntityListManager instance.

Parameters

mixed $entity Entity class path
array $criteria
array $ordering

Return Value

EntityListManager

ContactFormManager createContactFormManager()

Create and return a ContactFormManager to build and send contact form by email.

Return Value

ContactFormManager

EmailManager createEmailManager()

Create and return a EmailManager to build and send emails.

Return Value

EmailManager

protected UserInterface|null getUser()

Get a user from the tokenStorage.

Return Value

UserInterface|null

Exceptions

LogicException If tokenStorage is not available

See also

TokenInterface::getUser()

protected bool isGranted(mixed $attributes, mixed $object = null)

Checks if the attributes are granted against the current authentication token and optionally supplied object.

Parameters

mixed $attributes The attributes
mixed $object The object

Return Value

bool

Exceptions

LogicException