CONTROLLERs

SYMFONY2 - KRUNO KNEGO - LOCASTIC

NAMING CONVENTIONS

  • _controller: AcmeBundle:Default:index
  • Default == DefaultController
  • index == indexAction
  • DefaultController
  • indexAction

ROUTING

CONTROLLERS

NAMING CONVENTIONS

Acme\AcmeBundle\Controller\DefaultController::indexAction

FULLY QUALIFIED CLASS NAME

CONTROLLERS AS A SERVICE

acme_bundle.default::indexAction

GET THE REQUEST

GET THE REQUEST

  • app.php or app_dev.php
  • Router reads URI and matches it with _controller
  • Controller creates Response object
  • Client gets HTTP Headers + Content of Response object
  • Controller creates Response object

REQUESTS CONTROLLER RESPONSE CYCLE

GET THE REQUEST

GET THE REQUEST

ParameterBag, FileBag, HeaderBag, ServerBag

GET THE REQUEST

GET THE REQUEST

GET THE RESPONSE

GET THE RESPONSE

THE COOKIES

clearCookie() method

What are cookies?

THE SESSIONS

What are sessions?

What is the difference between sessions and cookies?

When would you use sessions and when would you use cookies?

THE SESSIONS

THE SESSIONS

THE SESSIONS

  • Session API
  • Session Workflow
  • Session Attributes
  • Session Metadata

http://symfony.com/doc/2.3/components/http_foundation/sessions.html

THE REDIRECTION

THE REDIRECTION

INTERNAL REDIRECTION

INTERNAL REDIRECTION

INTERNAL REDIRECTION

Sub-requests are expensive avoid if possible

404 pages

Triggers a 404 error response.

Other exceptions trigger 500 error response.

  • app_dev.php ( debug set to true )
  • app.php ( debug set to false -- can be changed )

404 pages

CUSTOM ERROR PAGES:

  1. Using default ExceptionController
  2. Replacing default ExceptionController with your own
  3. Using kernel exception event handling

EXERCISE

  • Create a controller that reads all GET requests and returns them as a response.

 

  • Create a custom error page. Check if it's working by using app.php front controller.

 

  • Create a controller that internally redirects to another controller and returns "Internal redirection works" as a response.

Controllers

By Kruno Knego

Controllers

Symfony2 Controllers. In-house education at Locastic.

  • 721
Loading comments...

More from Kruno Knego