Introduction to Symfony2
Andreas Hucks, SensioLabs Deutschland @meandmymonkey
What is Symfony2?
Symfony2 is a reusable set of standalone, decoupled, and cohesive PHP 5.3 components
that solve common web development problems.
Symfony2 is also a full-stack web framework.
http://localhost/.../web/app_dev.php/
Front Controller
Environment The "rst page
Separation of Concerns Implementation
Controller
View Model
/hello/fabien The Controller analyses the user request, calls the Model and passes data to the View.
The View layer formats data in a dedicated format (html, json…)
The Model stores the business logic and classes that manipulate data.
R
Router
Request
Glossary
An Application is a directory containing the con"guration for a given set of Bundles
A Bundle is a structured set of "les that implements a single feature and which can be easily shared with other developers.
Creating a new Bundle
Routing Con!guration
class HelloController { /** * @Route("/hello/{name}") */ public function helloAction($name) { // ... } }
Annotation Con"guration
The Controller Layer
Generating a response namespace Sensio\Bundle\TrainingBundle\Controller; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Symfony\Component\HttpFoundation\Response; class DefaultController { /** * @Route("/hello/{name}") */ public function indexAction($name) { return new Response(sprintf('Hello %s!', $name)); } }
The View Layer
// ... class DefaultController extends Controller { /** * @Route("/hello/{name}") */ public function indexAction($name) { $view = 'SensioTrainingBundle:Default:index.html.twig'; return $this->render($view, array('name' => $name)); } }
Rendering a view
Introduction to forms
Form
Data Source
POPO
Reads the data source
Reads the object
Writes the object
Normalization
Mapping
Validation