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
Afficher le fichier Open project: symfony/symfony Class Usage Examples

Méthodes protégées

Méthode 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 méthode

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 méthode

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
Résultat Symfony\Component\Security\Core\Exception\AccessDeniedException

createForm() protected méthode

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
Résultat Symfony\Component\Form\Form

createFormBuilder() protected méthode

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
Résultat Symfony\Component\Form\FormBuilder

createNotFoundException() protected méthode

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
Résultat Symfony\Component\HttpKernel\Exception\NotFoundHttpException

denyAccessUnlessGranted() protected méthode

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 méthode

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")
Résultat Symfony\Component\HttpFoundation\BinaryFileResponse

forward() protected méthode

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
Résultat Symfony\Component\HttpFoundation\Response A Response instance

generateUrl() protected méthode

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)
Résultat string The generated URL

get() protected méthode

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

getDoctrine() protected méthode

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

getParameter() protected méthode

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

getUser() protected méthode

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

has() protected méthode

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

isCsrfTokenValid() protected méthode

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
Résultat boolean

isGranted() protected méthode

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
Résultat boolean

json() protected méthode

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
Résultat Symfony\Component\HttpFoundation\JsonResponse

redirect() protected méthode

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
Résultat Symfony\Component\HttpFoundation\RedirectResponse

redirectToRoute() protected méthode

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
Résultat Symfony\Component\HttpFoundation\RedirectResponse

render() protected méthode

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
Résultat Symfony\Component\HttpFoundation\Response A Response instance

renderView() protected méthode

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
Résultat string The rendered view

stream() protected méthode

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
Résultat Symfony\Component\HttpFoundation\StreamedResponse A StreamedResponse instance