PHP Класс Symfony\Bundle\FrameworkBundle\Controller\Controller

It provides methods to common features needed in controllers.
Автор: Fabien Potencier ([email protected])
Наследование: extends Symfony\Component\DependencyInjection\ContainerAware
Показать файл Открыть проект Примеры использования класса

Защищенные методы

Метод Описание
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.

Описание методов

addFlash() защищенный Метод

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() защищенный Метод

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
Результат Symfony\Component\Security\Core\Exception\AccessDeniedException

createForm() защищенный Метод

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
Результат Symfony\Component\Form\Form

createFormBuilder() защищенный Метод

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
Результат Symfony\Component\Form\FormBuilder

createNotFoundException() защищенный Метод

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
Результат Symfony\Component\HttpKernel\Exception\NotFoundHttpException

denyAccessUnlessGranted() защищенный Метод

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() защищенный Метод

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")
Результат Symfony\Component\HttpFoundation\BinaryFileResponse

forward() защищенный Метод

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
Результат Symfony\Component\HttpFoundation\Response A Response instance

generateUrl() защищенный Метод

Generates a URL from the given parameters.
См. также: 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)
Результат string The generated URL

get() защищенный Метод

Gets a container service by its id.
protected get ( string $id ) : object
$id string The service id
Результат object The service

getDoctrine() защищенный Метод

Shortcut to return the Doctrine Registry service.
protected getDoctrine ( ) : Doctrine\Bundle\DoctrineBundle\Registry
Результат Doctrine\Bundle\DoctrineBundle\Registry

getParameter() защищенный Метод

Gets a container configuration parameter by its name.
protected getParameter ( string $name ) : mixed
$name string The parameter name
Результат mixed

getUser() защищенный Метод

Get a user from the Security Token Storage.
См. также: TokenInterface::getUser()
protected getUser ( ) : mixed
Результат mixed

has() защищенный Метод

Returns true if the service id is defined.
protected has ( string $id ) : boolean
$id string The service id
Результат boolean true if the service id is defined, false otherwise

isCsrfTokenValid() защищенный Метод

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
Результат boolean

isGranted() защищенный Метод

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
Результат boolean

json() защищенный Метод

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
Результат Symfony\Component\HttpFoundation\JsonResponse

redirect() защищенный Метод

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
Результат Symfony\Component\HttpFoundation\RedirectResponse

redirectToRoute() защищенный Метод

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
Результат Symfony\Component\HttpFoundation\RedirectResponse

render() защищенный Метод

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
Результат Symfony\Component\HttpFoundation\Response A Response instance

renderView() защищенный Метод

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
Результат string The rendered view

stream() защищенный Метод

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
Результат Symfony\Component\HttpFoundation\StreamedResponse A StreamedResponse instance