PHP Class Symfony\Bundle\FrameworkBundle\Controller\Controller

It provides methods to common features needed in controllers.
Author: Fabien Potencier ([email protected])
Inheritance: extends Symfony\Component\DependencyInjection\ContainerAware
Show file Open project: symfony/symfony Class Usage Examples

Protected Methods

Method Description
addFlash ( string $type, string $message ) Adds a flash message to the current session for type.
createAccessDeniedException ( string $message = 'Access Denied.', Exception $previous = null ) : Symfony\Component\Security\Core\Exception\AccessDeniedException Returns an AccessDeniedException.
createForm ( string $type, mixed $data = null, array $options = [] ) : Form Creates and returns a Form instance from the type of the form.
createFormBuilder ( mixed $data = null, array $options = [] ) : FormBuilder Creates and returns a form builder instance.
createNotFoundException ( string $message = 'Not Found', Exception $previous = null ) : NotFoundHttpException Returns a NotFoundHttpException.
denyAccessUnlessGranted ( mixed $attributes, mixed $object = null, string $message = 'Access Denied.' ) Throws an exception unless the attributes are granted against the current authentication token and optionally supplied object.
file ( SplFileInfo | string $file, string | null $fileName = null, string $disposition = ResponseHeaderBag::DISPOSITION_ATTACHMENT ) : BinaryFileResponse Returns a BinaryFileResponse object with original or customized file name and disposition header.
forward ( string $controller, array $path = [], array $query = [] ) : Response Forwards the request to another controller.
generateUrl ( string $route, mixed $parameters = [], integer $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH ) : string Generates a URL from the given parameters.
get ( string $id ) : object Gets a container service by its id.
getDoctrine ( ) : Doctrine\Bundle\DoctrineBundle\Registry Shortcut to return the Doctrine Registry service.
getParameter ( string $name ) : mixed Gets a container configuration parameter by its name.
getUser ( ) : mixed Get a user from the Security Token Storage.
has ( string $id ) : boolean Returns true if the service id is defined.
isCsrfTokenValid ( string $id, string $token ) : boolean Checks the validity of a CSRF token.
isGranted ( mixed $attributes, mixed $object = null ) : boolean Checks if the attributes are granted against the current authentication token and optionally supplied object.
json ( mixed $data, integer $status = 200, array $headers = [], array $context = [] ) : Symfony\Component\HttpFoundation\JsonResponse Returns a JsonResponse that uses the serializer component if enabled, or json_encode.
redirect ( string $url, integer $status = 302 ) : RedirectResponse Returns a RedirectResponse to the given URL.
redirectToRoute ( string $route, array $parameters = [], integer $status = 302 ) : RedirectResponse Returns a RedirectResponse to the given route with the given parameters.
render ( string $view, array $parameters = [], Response $response = null ) : Response Renders a view.
renderView ( string $view, array $parameters = [] ) : string Returns a rendered view.
stream ( string $view, array $parameters = [], Symfony\Component\HttpFoundation\StreamedResponse $response = null ) : Symfony\Component\HttpFoundation\StreamedResponse Streams a view.

Method Details

addFlash() protected method

Adds a flash message to the current session for type.
protected addFlash ( string $type, string $message )
$type string The type
$message string The message

createAccessDeniedException() protected method

This will result in a 403 response code. Usage example: throw $this->createAccessDeniedException('Unable to access this page!');
protected createAccessDeniedException ( string $message = 'Access Denied.', Exception $previous = null ) : Symfony\Component\Security\Core\Exception\AccessDeniedException
$message string A message
$previous Exception The previous exception
return Symfony\Component\Security\Core\Exception\AccessDeniedException

createForm() protected method

Creates and returns a Form instance from the type of the form.
protected createForm ( string $type, mixed $data = null, array $options = [] ) : Form
$type string The fully qualified class name of the form type
$data mixed The initial data for the form
$options array Options for the form
return Symfony\Component\Form\Form

createFormBuilder() protected method

Creates and returns a form builder instance.
protected createFormBuilder ( mixed $data = null, array $options = [] ) : FormBuilder
$data mixed The initial data for the form
$options array Options for the form
return Symfony\Component\Form\FormBuilder

createNotFoundException() protected method

This will result in a 404 response code. Usage example: throw $this->createNotFoundException('Page not found!');
protected createNotFoundException ( string $message = 'Not Found', Exception $previous = null ) : NotFoundHttpException
$message string A message
$previous Exception The previous exception
return Symfony\Component\HttpKernel\Exception\NotFoundHttpException

denyAccessUnlessGranted() protected method

Throws an exception unless the attributes are granted against the current authentication token and optionally supplied object.
protected denyAccessUnlessGranted ( mixed $attributes, mixed $object = null, string $message = 'Access Denied.' )
$attributes mixed The attributes
$object mixed The object
$message string The message passed to the exception

file() protected method

Returns a BinaryFileResponse object with original or customized file name and disposition header.
protected file ( SplFileInfo | string $file, string | null $fileName = null, string $disposition = ResponseHeaderBag::DISPOSITION_ATTACHMENT ) : BinaryFileResponse
$file SplFileInfo | string File object or path to file to be sent as response
$fileName string | null File name to be sent to response or null (will use original file name)
$disposition string Disposition of response ("attachment" is default, other type is "inline")
return Symfony\Component\HttpFoundation\BinaryFileResponse

forward() protected method

Forwards the request to another controller.
protected forward ( string $controller, array $path = [], array $query = [] ) : Response
$controller string The controller name (a string like BlogBundle:Post:index)
$path array An array of path parameters
$query array An array of query parameters
return Symfony\Component\HttpFoundation\Response A Response instance

generateUrl() protected method

Generates a URL from the given parameters.
See also: UrlGeneratorInterface
protected generateUrl ( string $route, mixed $parameters = [], integer $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH ) : string
$route string The name of the route
$parameters mixed An array of parameters
$referenceType integer The type of reference (one of the constants in UrlGeneratorInterface)
return string The generated URL

get() protected method

Gets a container service by its id.
protected get ( string $id ) : object
$id string The service id
return object The service

getDoctrine() protected method

Shortcut to return the Doctrine Registry service.
protected getDoctrine ( ) : Doctrine\Bundle\DoctrineBundle\Registry
return Doctrine\Bundle\DoctrineBundle\Registry

getParameter() protected method

Gets a container configuration parameter by its name.
protected getParameter ( string $name ) : mixed
$name string The parameter name
return mixed

getUser() protected method

Get a user from the Security Token Storage.
See also: TokenInterface::getUser()
protected getUser ( ) : mixed
return mixed

has() protected method

Returns true if the service id is defined.
protected has ( string $id ) : boolean
$id string The service id
return boolean true if the service id is defined, false otherwise

isCsrfTokenValid() protected method

Checks the validity of a CSRF token.
protected isCsrfTokenValid ( string $id, string $token ) : boolean
$id string The id used when generating the token
$token string The actual token sent with the request that should be validated
return boolean

isGranted() protected method

Checks if the attributes are granted against the current authentication token and optionally supplied object.
protected isGranted ( mixed $attributes, mixed $object = null ) : boolean
$attributes mixed The attributes
$object mixed The object
return boolean

json() protected method

Returns a JsonResponse that uses the serializer component if enabled, or json_encode.
protected json ( mixed $data, integer $status = 200, array $headers = [], array $context = [] ) : Symfony\Component\HttpFoundation\JsonResponse
$data mixed The response data
$status integer The status code to use for the Response
$headers array Array of extra headers to add
$context array Context to pass to serializer when using serializer component
return Symfony\Component\HttpFoundation\JsonResponse

redirect() protected method

Returns a RedirectResponse to the given URL.
protected redirect ( string $url, integer $status = 302 ) : RedirectResponse
$url string The URL to redirect to
$status integer The status code to use for the Response
return Symfony\Component\HttpFoundation\RedirectResponse

redirectToRoute() protected method

Returns a RedirectResponse to the given route with the given parameters.
protected redirectToRoute ( string $route, array $parameters = [], integer $status = 302 ) : RedirectResponse
$route string The name of the route
$parameters array An array of parameters
$status integer The status code to use for the Response
return Symfony\Component\HttpFoundation\RedirectResponse

render() protected method

Renders a view.
protected render ( string $view, array $parameters = [], Response $response = null ) : Response
$view string The view name
$parameters array An array of parameters to pass to the view
$response Symfony\Component\HttpFoundation\Response A response instance
return Symfony\Component\HttpFoundation\Response A Response instance

renderView() protected method

Returns a rendered view.
protected renderView ( string $view, array $parameters = [] ) : string
$view string The view name
$parameters array An array of parameters to pass to the view
return string The rendered view

stream() protected method

Streams a view.
protected stream ( string $view, array $parameters = [], Symfony\Component\HttpFoundation\StreamedResponse $response = null ) : Symfony\Component\HttpFoundation\StreamedResponse
$view string The view name
$parameters array An array of parameters to pass to the view
$response Symfony\Component\HttpFoundation\StreamedResponse A response instance
return Symfony\Component\HttpFoundation\StreamedResponse A StreamedResponse instance