Introduction to Symfony2 - Zendstatic.zend.com/topics/Symfony2-20130912.pdf · Symfony2 is a...

17

Transcript of Introduction to Symfony2 - Zendstatic.zend.com/topics/Symfony2-20130912.pdf · Symfony2 is a...

Page 1: Introduction to Symfony2 - Zendstatic.zend.com/topics/Symfony2-20130912.pdf · Symfony2 is a reusable set of standalone, decoupled, and cohesive PHP 5.3 components that solve common
Page 2: Introduction to Symfony2 - Zendstatic.zend.com/topics/Symfony2-20130912.pdf · Symfony2 is a reusable set of standalone, decoupled, and cohesive PHP 5.3 components that solve common

Introduction to Symfony2

Andreas Hucks, SensioLabs Deutschland @meandmymonkey

Page 3: Introduction to Symfony2 - Zendstatic.zend.com/topics/Symfony2-20130912.pdf · Symfony2 is a reusable set of standalone, decoupled, and cohesive PHP 5.3 components that solve common

What is Symfony2?

Page 4: Introduction to Symfony2 - Zendstatic.zend.com/topics/Symfony2-20130912.pdf · Symfony2 is a reusable set of standalone, decoupled, and cohesive PHP 5.3 components that solve common

Symfony2 is a reusable set of standalone, decoupled, and cohesive PHP 5.3 components

that solve common web development problems.

Page 5: Introduction to Symfony2 - Zendstatic.zend.com/topics/Symfony2-20130912.pdf · Symfony2 is a reusable set of standalone, decoupled, and cohesive PHP 5.3 components that solve common

Symfony2 is also a full-stack web framework.

Page 6: Introduction to Symfony2 - Zendstatic.zend.com/topics/Symfony2-20130912.pdf · Symfony2 is a reusable set of standalone, decoupled, and cohesive PHP 5.3 components that solve common
Page 7: Introduction to Symfony2 - Zendstatic.zend.com/topics/Symfony2-20130912.pdf · Symfony2 is a reusable set of standalone, decoupled, and cohesive PHP 5.3 components that solve common

http://localhost/.../web/app_dev.php/

Front  Controller  

Environment  The "rst page

Page 8: Introduction to Symfony2 - Zendstatic.zend.com/topics/Symfony2-20130912.pdf · Symfony2 is a reusable set of standalone, decoupled, and cohesive PHP 5.3 components that solve common

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

Page 9: Introduction to Symfony2 - Zendstatic.zend.com/topics/Symfony2-20130912.pdf · Symfony2 is a reusable set of standalone, decoupled, and cohesive PHP 5.3 components that solve common

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.

Page 10: Introduction to Symfony2 - Zendstatic.zend.com/topics/Symfony2-20130912.pdf · Symfony2 is a reusable set of standalone, decoupled, and cohesive PHP 5.3 components that solve common

Creating a new Bundle

Page 11: Introduction to Symfony2 - Zendstatic.zend.com/topics/Symfony2-20130912.pdf · Symfony2 is a reusable set of standalone, decoupled, and cohesive PHP 5.3 components that solve common

Routing Con!guration

Page 12: Introduction to Symfony2 - Zendstatic.zend.com/topics/Symfony2-20130912.pdf · Symfony2 is a reusable set of standalone, decoupled, and cohesive PHP 5.3 components that solve common

class HelloController { /** * @Route("/hello/{name}") */ public function helloAction($name) { // ... } }

Annotation Con"guration

Page 13: Introduction to Symfony2 - Zendstatic.zend.com/topics/Symfony2-20130912.pdf · Symfony2 is a reusable set of standalone, decoupled, and cohesive PHP 5.3 components that solve common

The Controller Layer

Page 14: Introduction to Symfony2 - Zendstatic.zend.com/topics/Symfony2-20130912.pdf · Symfony2 is a reusable set of standalone, decoupled, and cohesive PHP 5.3 components that solve common

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)); } }

Page 15: Introduction to Symfony2 - Zendstatic.zend.com/topics/Symfony2-20130912.pdf · Symfony2 is a reusable set of standalone, decoupled, and cohesive PHP 5.3 components that solve common

The View Layer

Page 16: Introduction to Symfony2 - Zendstatic.zend.com/topics/Symfony2-20130912.pdf · Symfony2 is a reusable set of standalone, decoupled, and cohesive PHP 5.3 components that solve common

// ... 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

Page 17: Introduction to Symfony2 - Zendstatic.zend.com/topics/Symfony2-20130912.pdf · Symfony2 is a reusable set of standalone, decoupled, and cohesive PHP 5.3 components that solve common

Introduction to forms

Form

Data Source

POPO

Reads the data source

Reads the object

Writes the object

Normalization

Mapping

Validation