Class

Symfony\Bundle\FrameworkBundle\Controller\Controller

class Controller extends ContainerAware

Controller is a simple implementation of a Controller.

It provides methods to common features needed in controllers.

Methods

setContainer(ContainerInterface $container = null)

Sets the Container.

from ContainerAware
string generateUrl(string $route, mixed $parameters = array(), bool|string $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH)

Generates a URL from the given parameters.

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

Forwards the request to another controller.

RedirectResponse redirect(string $url, int $status = 302)

Returns a RedirectResponse to the given URL.

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

Returns a rendered view.

Response render(string $view, array $parameters = array(), Response $response = null)

Renders a view.

StreamedResponse stream(string $view, array $parameters = array(), StreamedResponse $response = null)

Streams a view.

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 = array())

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

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

Creates and returns a form builder instance

Request getRequest()

Shortcut to return the request service.

Registry getDoctrine()

Shortcut to return the Doctrine Registry service.

mixed getUser()

Get a user from the Security Context

bool has(string $id)

Returns true if the service id is defined.

object get(string $id)

Gets a service by id.

Details

in ContainerAware at line 37
public setContainer(ContainerInterface $container = null)

Sets the Container.

Parameters

ContainerInterface $container A ContainerInterface instance

at line 48
public string generateUrl(string $route, mixed $parameters = array(), bool|string $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH)

Generates a URL from the given parameters.

Parameters

string $route The name of the route
mixed $parameters An array of parameters
bool|string $referenceType The type of reference (one of the constants in UrlGeneratorInterface)

Return Value

string The generated URL

See also

UrlGeneratorInterface

at line 62
public Response forward(string $controller, array $path = array(), array $query = array())

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

at line 78
public RedirectResponse redirect(string $url, int $status = 302)

Returns a RedirectResponse to the given URL.

Parameters

string $url The URL to redirect to
int $status The status code to use for the Response

Return Value

RedirectResponse

at line 91
public string renderView(string $view, array $parameters = array())

Returns a rendered view.

Parameters

string $view The view name
array $parameters An array of parameters to pass to the view

Return Value

string The rendered view

at line 105
public Response render(string $view, array $parameters = array(), Response $response = null)

Renders a view.

Parameters

string $view The view name
array $parameters An array of parameters to pass to the view
Response $response A response instance

Return Value

Response A Response instance

at line 119
public StreamedResponse stream(string $view, array $parameters = array(), StreamedResponse $response = null)

Streams a view.

Parameters

string $view The view name
array $parameters An array of parameters to pass to the view
StreamedResponse $response A response instance

Return Value

StreamedResponse A StreamedResponse instance

at line 148
public 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

at line 165
public 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

at line 179
public Form createForm(string|FormTypeInterface $type, mixed $data = null, array $options = array())

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

at line 192
public FormBuilder createFormBuilder(mixed $data = null, array $options = array())

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

at line 206
public Request getRequest()

Shortcut to return the request service.

Return Value

Request

at line 218
public Registry getDoctrine()

Shortcut to return the Doctrine Registry service.

Return Value

Registry

Exceptions

LogicException If DoctrineBundle is not available

at line 236
public mixed getUser()

Get a user from the Security Context

Return Value

mixed

Exceptions

LogicException If SecurityBundle is not available

See also

Symfony\Component\Security\Core\Authentication\Token\TokenInterface::getUser()

at line 260
public bool has(string $id)

Returns true if the service id is defined.

Parameters

string $id The service id

Return Value

bool true if the service id is defined, false otherwise

at line 272
public object get(string $id)

Gets a service by id.

Parameters

string $id The service id

Return Value

object The service