symfony - introduction

200
A Better Way to Build Thursday, 27 September 12

Upload: piers-warmers

Post on 16-Jul-2015

110 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Symfony - Introduction

A Better Way to Build

Thursday, 27 September 12

Page 2: Symfony - Introduction

Piers Warmers

@warmers

@pierswarmers

Thursday, 27 September 12

Page 3: Symfony - Introduction

What’s on tonight?

Thursday, 27 September 12

Page 4: Symfony - Introduction

Session 1.

Thursday, 27 September 12

Page 5: Symfony - Introduction

Session 1.

• Introduction

Thursday, 27 September 12

Page 6: Symfony - Introduction

Session 1.

• Introduction

• What is Symfony?

Thursday, 27 September 12

Page 7: Symfony - Introduction

Session 1.

• Introduction

• What is Symfony?

• Core concepts

Thursday, 27 September 12

Page 8: Symfony - Introduction

Session 1.

• Introduction

• What is Symfony?

• Core concepts

• A typical application

Thursday, 27 September 12

Page 9: Symfony - Introduction

Session 1.

• Introduction

• What is Symfony?

• Core concepts

• A typical application

• Lets code!

Thursday, 27 September 12

Page 10: Symfony - Introduction

Session 2.

Thursday, 27 September 12

Page 11: Symfony - Introduction

Session 2.

• CRUD and MVC (with the model)

Thursday, 27 September 12

Page 12: Symfony - Introduction

Session 2.

• CRUD and MVC (with the model)

• Cleaning up our interfaces

Thursday, 27 September 12

Page 13: Symfony - Introduction

Session 2.

• CRUD and MVC (with the model)

• Cleaning up our interfaces

• Forms and validation

Thursday, 27 September 12

Page 14: Symfony - Introduction

Session 2.

• CRUD and MVC (with the model)

• Cleaning up our interfaces

• Forms and validation

• Services and dependancy injection

Thursday, 27 September 12

Page 15: Symfony - Introduction

Session 2.

• CRUD and MVC (with the model)

• Cleaning up our interfaces

• Forms and validation

• Services and dependancy injection

• An overview of security

Thursday, 27 September 12

Page 16: Symfony - Introduction

Session 2.

• CRUD and MVC (with the model)

• Cleaning up our interfaces

• Forms and validation

• Services and dependancy injection

• An overview of security

• Using Symfony components without symfony

Thursday, 27 September 12

Page 17: Symfony - Introduction

Session 2.

• CRUD and MVC (with the model)

• Cleaning up our interfaces

• Forms and validation

• Services and dependancy injection

• An overview of security

• Using Symfony components without symfony

Thursday, 27 September 12

Page 18: Symfony - Introduction

ce qui est Symfony?

Thursday, 27 September 12

Page 19: Symfony - Introduction

Symfony is…

Thursday, 27 September 12

Page 20: Symfony - Introduction

Symfony is…

• a full stack framework (PHP 5.3+)

Thursday, 27 September 12

Page 21: Symfony - Introduction

“Symfony is a reusable set of standalone, decoupled and cohesive PHP components that solve common

web development problems”Dries Buytaert (Founder of Drupal)

Thursday, 27 September 12

Page 22: Symfony - Introduction

Problems?

Thursday, 27 September 12

Page 23: Symfony - Introduction

Problems?

• Connect requests to business logic (route ➜ code)

Thursday, 27 September 12

Page 24: Symfony - Introduction

Problems?

• Connect requests to business logic (route ➜ code)

• Handle environment configuration (dev, test, prod)

Thursday, 27 September 12

Page 25: Symfony - Introduction

Problems?

• Connect requests to business logic (route ➜ code)

• Handle environment configuration (dev, test, prod)

• Secure an application (authentication, firewalls)

Thursday, 27 September 12

Page 26: Symfony - Introduction

Problems?

• Connect requests to business logic (route ➜ code)

• Handle environment configuration (dev, test, prod)

• Secure an application (authentication, firewalls)

• Render a response (templates)

Thursday, 27 September 12

Page 27: Symfony - Introduction

Problems?

• Connect requests to business logic (route ➜ code)

• Handle environment configuration (dev, test, prod)

• Secure an application (authentication, firewalls)

• Render a response (templates)

• Speed things up (compiling, caching, ESI, proxies)

Thursday, 27 September 12

Page 28: Symfony - Introduction

Problems?

• Connect requests to business logic (route ➜ code)

• Handle environment configuration (dev, test, prod)

• Secure an application (authentication, firewalls)

• Render a response (templates)

• Speed things up (compiling, caching, ESI, proxies)

• I18N & L10N (translations, regional formatting)

Thursday, 27 September 12

Page 29: Symfony - Introduction

Standalone, decoupled?

Thursday, 27 September 12

Page 30: Symfony - Introduction

Symfony & Components

BrowserKit

ClassLoader

Config

Console

CssSelector

DependencyInjection

DomCrawler

EventDispatcher

Finder

Form

HttpFoundation

HttpKernel

Locale

Process

Routing

Security

Serializer

Templating

Translation

Validator

Yaml

includes

See: http://symfony.com/components

Thursday, 27 September 12

Page 32: Symfony - Introduction

Drupal & Symfony

BrowserKit

ClassLoader

Config

Console

CssSelector

DependencyInjection

DomCrawler

EventDispatcher

Finder

Form

HttpFoundation

HttpKernel

Locale

Process

Routing

Security

Serializer

Templating

Translation

Validator

Yaml

using

Version 8+

Thursday, 27 September 12

Page 33: Symfony - Introduction

https://github.com/drupal/drupal/blob/8.x/index.php

Thursday, 27 September 12

Page 34: Symfony - Introduction

Symfony is…

• a full stack framework (PHP 5.3+) ✓

Thursday, 27 September 12

Page 35: Symfony - Introduction

Symfony is…

• a full stack framework (PHP 5.3+) ✓

• application methodology (best practices, standards)

Thursday, 27 September 12

Page 36: Symfony - Introduction

“A most important, but also most elusive, aspect of any tool is its

influence on the habits of those who

train themselves in its use.”Edsger Dijkstra (Computer Scientist)

Thursday, 27 September 12

Page 37: Symfony - Introduction

Influence by example…

Thursday, 27 September 12

Page 38: Symfony - Introduction

Influence by example…

• a blueprint for applications (shape, vernacular)

Thursday, 27 September 12

Page 39: Symfony - Introduction

Influence by example…

• a blueprint for applications (shape, vernacular)

• best practices (quality, testing)

Thursday, 27 September 12

Page 40: Symfony - Introduction

Influence by example…

• a blueprint for applications (shape, vernacular)

• best practices (quality, testing)

• standardisation and consistency (PSR-0, PSR-1, PSR-2)

Thursday, 27 September 12

Page 41: Symfony - Introduction

Symfony is…

• a full stack framework (PHP 5.3+) ✓

• application methodology (best practices, standards) ✓

Thursday, 27 September 12

Page 42: Symfony - Introduction

Symfony is…

• a full stack framework (PHP 5.3+) ✓

• application methodology (best practices, standards) ✓

• an enthusiastic community (it’s about people)

Thursday, 27 September 12

Page 43: Symfony - Introduction

…and theres lots of them!

Thursday, 27 September 12

Page 44: Symfony - Introduction

…and theres lots of them!

• large community (http://connect.sensiolabs.com)

Thursday, 27 September 12

Page 45: Symfony - Introduction

…and theres lots of them!

• large community (http://connect.sensiolabs.com)

• regional events (SymfonyLive - Paris, London, Berlin, San Francisco)

Thursday, 27 September 12

Page 46: Symfony - Introduction

…and theres lots of them!

• large community (http://connect.sensiolabs.com)

• regional events (SymfonyLive - Paris, London, Berlin, San Francisco)

• involved (http://symfony.com/contributors)

Thursday, 27 September 12

Page 47: Symfony - Introduction

…and theres lots of them!

• large community (http://connect.sensiolabs.com)

• regional events (SymfonyLive - Paris, London, Berlin, San Francisco)

• involved (http://symfony.com/contributors)

• like to share (open source, permissive MIT style)

Thursday, 27 September 12

Page 48: Symfony - Introduction

Symfony is…

• a full stack framework (PHP 5.3+) ✓

• application methodology (best practices, standards) ✓

Thursday, 27 September 12

Page 49: Symfony - Introduction

Symfony is…

• a full stack framework (PHP 5.3+) ✓

• application methodology (best practices, standards) ✓

• an enthusiastic community (it’s about people) ✓

Thursday, 27 September 12

Page 50: Symfony - Introduction

Lets Go!Time to setup a project.

Thursday, 27 September 12

Page 51: Symfony - Introduction

Installation in three steps

Thursday, 27 September 12

Page 52: Symfony - Introduction

Installation in three steps

• get composer

Thursday, 27 September 12

Page 53: Symfony - Introduction

Installation in three steps

• get composer

• create project

Thursday, 27 September 12

Page 54: Symfony - Introduction

Installation in three steps

• get composer

• create project

• start server

Thursday, 27 September 12

Page 55: Symfony - Introduction

Dependency management

Satis

Thursday, 27 September 12

Page 56: Symfony - Introduction

So the installation in three steps…

Thursday, 27 September 12

Page 57: Symfony - Introduction

So the installation in three steps…

Thursday, 27 September 12

Page 58: Symfony - Introduction

Get composer - it’s crazy simple!

Thursday, 27 September 12

Page 59: Symfony - Introduction

Get composer - it’s crazy simple!

Thursday, 27 September 12

Page 60: Symfony - Introduction

Get composer - it’s crazy simple!

Thursday, 27 September 12

Page 61: Symfony - Introduction

Get composer - it’s crazy simple!

Thursday, 27 September 12

Page 62: Symfony - Introduction

Create a project

Thursday, 27 September 12

Page 63: Symfony - Introduction

Create a project

Thursday, 27 September 12

Page 64: Symfony - Introduction

Create a project

Thursday, 27 September 12

Page 65: Symfony - Introduction

Create a project

Thursday, 27 September 12

Page 66: Symfony - Introduction

Run the server, we’re online!

Thursday, 27 September 12

Page 67: Symfony - Introduction

Lets look inside ./demo1

Thursday, 27 September 12

Page 68: Symfony - Introduction

Lets look inside ./demo1

Thursday, 27 September 12

Page 69: Symfony - Introduction

The important parts…

Thursday, 27 September 12

Page 70: Symfony - Introduction

The important parts…

• app ➜ AppKernal, cache, configuration, logs, console

Thursday, 27 September 12

Page 71: Symfony - Introduction

The important parts…

• app ➜ AppKernal, cache, configuration, logs, console

• composer.json ➜ dependancy map

Thursday, 27 September 12

Page 72: Symfony - Introduction

The important parts…

• app ➜ AppKernal, cache, configuration, logs, console

• composer.json ➜ dependancy map

• composer.lock ➜ what was actually installed

Thursday, 27 September 12

Page 73: Symfony - Introduction

The important parts…

• app ➜ AppKernal, cache, configuration, logs, console

• composer.json ➜ dependancy map

• composer.lock ➜ what was actually installed

• src ➜ you’re code goes here

Thursday, 27 September 12

Page 74: Symfony - Introduction

The important parts…

• app ➜ AppKernal, cache, configuration, logs, console

• composer.json ➜ dependancy map

• composer.lock ➜ what was actually installed

• src ➜ you’re code goes here

• vendor ➜ other peoples code goes here (via composer)

Thursday, 27 September 12

Page 75: Symfony - Introduction

The important parts…

• app ➜ AppKernal, cache, configuration, logs, console

• composer.json ➜ dependancy map

• composer.lock ➜ what was actually installed

• src ➜ you’re code goes here

• vendor ➜ other peoples code goes here (via composer)

• web ➜ server loads app.php here which loads…

Thursday, 27 September 12

Page 76: Symfony - Introduction

The important parts…

• app ➜ AppKernal, cache, configuration, logs, console

• composer.json ➜ dependancy map

• composer.lock ➜ what was actually installed

• src ➜ you’re code goes here

• vendor ➜ other peoples code goes here (via composer)

• web ➜ server loads app.php here which loads…

AppKernal.php

Thursday, 27 September 12

Page 77: Symfony - Introduction

In the browser

Thursday, 27 September 12

Page 78: Symfony - Introduction

The console

Thursday, 27 September 12

Page 79: Symfony - Introduction

./app/console

Thursday, 27 September 12

Page 80: Symfony - Introduction

The console

Thursday, 27 September 12

Page 81: Symfony - Introduction

The console

• Time savers: build models, controllers and bundles

Thursday, 27 September 12

Page 82: Symfony - Introduction

The console

• Time savers: build models, controllers and bundles

• Manage cache removal

Thursday, 27 September 12

Page 83: Symfony - Introduction

The console

• Time savers: build models, controllers and bundles

• Manage cache removal

• Update database schema

Thursday, 27 September 12

Page 84: Symfony - Introduction

The console

• Time savers: build models, controllers and bundles

• Manage cache removal

• Update database schema

• Send spooled emails

Thursday, 27 September 12

Page 85: Symfony - Introduction

The console

• Time savers: build models, controllers and bundles

• Manage cache removal

• Update database schema

• Send spooled emails

• Build you own CLI tasks

Thursday, 27 September 12

Page 86: Symfony - Introduction

The console

• Time savers: build models, controllers and bundles

• Manage cache removal

• Update database schema

• Send spooled emails

• Build you own CLI tasks

• Run the PHP test server

Thursday, 27 September 12

Page 87: Symfony - Introduction

Built in PHP server is good for quick testing but... don’t use in production!

Thursday, 27 September 12

Page 88: Symfony - Introduction

What’s my normal setup?

Thursday, 27 September 12

Page 89: Symfony - Introduction

What’s my normal setup?

• PHP 5.4.6

Thursday, 27 September 12

Page 90: Symfony - Introduction

What’s my normal setup?

• PHP 5.4.6

• MySQL 5.5.25a MySQL Community Server

Thursday, 27 September 12

Page 91: Symfony - Introduction

What’s my normal setup?

• PHP 5.4.6

• MySQL 5.5.25a MySQL Community Server

• Apache HTTP Server 2.2.22

Thursday, 27 September 12

Page 92: Symfony - Introduction

Let’s look at the config…

Thursday, 27 September 12

Page 93: Symfony - Introduction

Configure: hosts

Thursday, 27 September 12

Page 94: Symfony - Introduction

Configure: Apache HTTP

Thursday, 27 September 12

Page 95: Symfony - Introduction

Configure: MySQL CE

Thursday, 27 September 12

Page 96: Symfony - Introduction

Through Apache

Thursday, 27 September 12

Page 97: Symfony - Introduction

The Web Debug Toolbar

Thursday, 27 September 12

Page 98: Symfony - Introduction

Web Debug Toolbar

Thursday, 27 September 12

Page 99: Symfony - Introduction

Web Debug Toolbar

• Displays resource usage

Thursday, 27 September 12

Page 100: Symfony - Introduction

Web Debug Toolbar

• Displays resource usage

• Monitors code execution times

Thursday, 27 September 12

Page 101: Symfony - Introduction

Web Debug Toolbar

• Displays resource usage

• Monitors code execution times

• Presents info on session, logs, exceptions

Thursday, 27 September 12

Page 102: Symfony - Introduction

Web Debug Toolbar

• Displays resource usage

• Monitors code execution times

• Presents info on session, logs, exceptions

• Provides insight into persistence layer

Thursday, 27 September 12

Page 103: Symfony - Introduction

Web Debug Toolbar

• Displays resource usage

• Monitors code execution times

• Presents info on session, logs, exceptions

• Provides insight into persistence layer

• Good for showing off in meetings

Thursday, 27 September 12

Page 104: Symfony - Introduction

“Hello world!”The Demo App

Thursday, 27 September 12

Page 105: Symfony - Introduction

What’s just happened?

Route

htpp://…/hello/SydPHP

Request

Controller

View

Thursday, 27 September 12

Page 106: Symfony - Introduction

What’s just happened?

/demo/hello/{name}

htpp://…/demo/hello/SydPHP

authentication, authorisation, resolving etc…

AcmeDemoBundle->helloAction($name)

hello.html.twig

layout.html.twig

Thursday, 27 September 12

Page 107: Symfony - Introduction

./app/config/routing_dev.yml

Thursday, 27 September 12

Page 108: Symfony - Introduction

./src/Acme/DemoBundle/Controller/DemoController.php

Thursday, 27 September 12

Page 109: Symfony - Introduction

./src/Acme/DemoBundle/Resources/views/Demo/hello.html.twig

Thursday, 27 September 12

Page 110: Symfony - Introduction

A template enginefor PHP?

Thursday, 27 September 12

Page 111: Symfony - Introduction

Twig template engine

Thursday, 27 September 12

Page 112: Symfony - Introduction

Twig template engine

• Fast (compiled to optimised PHP)

Thursday, 27 September 12

Page 113: Symfony - Introduction

Twig template engine

• Fast (compiled to optimised PHP)

• Concise (easy to learn, clean, designers will love you)

Thursday, 27 September 12

Page 114: Symfony - Introduction

For example:

Output in PHP:

Output in Twig:

Thursday, 27 September 12

Page 115: Symfony - Introduction

For example:

Output in PHP:

Output in Twig:

Thursday, 27 September 12

Page 116: Symfony - Introduction

Twig templating

• Fast (compiled to optimised PHP)

• Concise (easy to learn, clean, designers will love you)

Thursday, 27 September 12

Page 117: Symfony - Introduction

Twig templating

• Fast (compiled to optimised PHP)

• Concise (easy to learn, clean, designers will love you)

• Secure (escaped output, sandboxed)

Thursday, 27 September 12

Page 118: Symfony - Introduction

Twig templating

• Fast (compiled to optimised PHP)

• Concise (easy to learn, clean, designers will love you)

• Secure (escaped output, sandboxed)

• Extendable (custom tags and filters)

Thursday, 27 September 12

Page 119: Symfony - Introduction

Twig templating

• Fast (compiled to optimised PHP)

• Concise (easy to learn, clean, designers will love you)

• Secure (escaped output, sandboxed)

• Extendable (custom tags and filters)

• Helps enforce SoC (helps keep templates for display only)

Thursday, 27 September 12

Page 120: Symfony - Introduction

Twig templating

• Fast (compiled to optimised PHP)

• Concise (easy to learn, clean, designers will love you)

• Secure (escaped output, sandboxed)

• Extendable (custom tags and filters)

• Helps enforce SoC (helps keep templates for display only)

• Totally optional (you can still use PHP or both)

Thursday, 27 September 12

Page 121: Symfony - Introduction

Twig templating

• Fast (compiled to optimised PHP)

• Concise (easy to learn, clean, designers will love you)

• Secure (escaped output, sandboxed)

• Extendable (custom tags and filters)

• Helps enforce SoC (helps keep templates for display only)

• Totally optional (you can still use PHP or both)

Thursday, 27 September 12

Page 122: Symfony - Introduction

Twig templates can extend Layouts

Thursday, 27 September 12

Page 123: Symfony - Introduction

(simplified)./src/Acme/DemoBundle/Resources/views/layout.html.twig

Thursday, 27 September 12

Page 124: Symfony - Introduction

Coming up…

Thursday, 27 September 12

Page 125: Symfony - Introduction

Coming up…

• CRUD and MVC (with the model)

Thursday, 27 September 12

Page 126: Symfony - Introduction

Coming up…

• CRUD and MVC (with the model)

• Cleaning up our interfaces

Thursday, 27 September 12

Page 127: Symfony - Introduction

Coming up…

• CRUD and MVC (with the model)

• Cleaning up our interfaces

• Forms and validation

Thursday, 27 September 12

Page 128: Symfony - Introduction

Coming up…

• CRUD and MVC (with the model)

• Cleaning up our interfaces

• Forms and validation

• Services and dependancy injection

Thursday, 27 September 12

Page 129: Symfony - Introduction

Coming up…

• CRUD and MVC (with the model)

• Cleaning up our interfaces

• Forms and validation

• Services and dependancy injection

• An overview of security

Thursday, 27 September 12

Page 130: Symfony - Introduction

Coming up…

• CRUD and MVC (with the model)

• Cleaning up our interfaces

• Forms and validation

• Services and dependancy injection

• An overview of security

• Using Symfony components without symfony

Thursday, 27 September 12

Page 131: Symfony - Introduction

big thanks to

SensioLabs

PizzaTime!

Thursday, 27 September 12

Page 132: Symfony - Introduction

Quick recap…

Thursday, 27 September 12

Page 133: Symfony - Introduction

Quick recap…

• We have a simple application setup

Thursday, 27 September 12

Page 134: Symfony - Introduction

Quick recap…

• We have a simple application setup

• We’ve looked at:

Thursday, 27 September 12

Page 135: Symfony - Introduction

Quick recap…

• We have a simple application setup

• We’ve looked at:

• routing

Thursday, 27 September 12

Page 136: Symfony - Introduction

Quick recap…

• We have a simple application setup

• We’ve looked at:

• routing

• controllers

Thursday, 27 September 12

Page 137: Symfony - Introduction

Quick recap…

• We have a simple application setup

• We’ve looked at:

• routing

• controllers

• templates

Thursday, 27 September 12

Page 138: Symfony - Introduction

Quick recap…

• We have a simple application setup

• We’ve looked at:

• routing

• controllers

• templates

• Lets build a simple CRUD application

Thursday, 27 September 12

Page 139: Symfony - Introduction

CRUD and MVC

Route

htpp://…/products

Request

Controller

Model View

Thursday, 27 September 12

Page 140: Symfony - Introduction

Doctrine DBAL and ORM

Thursday, 27 September 12

Page 141: Symfony - Introduction

Before we get started…

Thursday, 27 September 12

Page 142: Symfony - Introduction

Bundles & namespacesare your friends…

Thursday, 27 September 12

Page 143: Symfony - Introduction

Bundles & namespacesare your friends…

image by sergiu_bacioiu @

Thursday, 27 September 12

Page 144: Symfony - Introduction

• Make life simpler (after some wtf moments)

Thursday, 27 September 12

Page 145: Symfony - Introduction

• Make life simpler (after some wtf moments)

• Should follow FIG standards (www.php-fig.org)

Thursday, 27 September 12

Page 146: Symfony - Introduction

• Make life simpler (after some wtf moments)

• Should follow FIG standards (www.php-fig.org)

• Makes autoloading a breeze (ClassLoader component)

See here: http://symfony.com/doc/current/components/class_loader.html

Thursday, 27 September 12

Page 147: Symfony - Introduction

• \Zend\Mail\Message ➜

/path/to/project/lib/vendor/Zend/Mail/Message.php

Thursday, 27 September 12

Page 148: Symfony - Introduction

• \Zend\Mail\Message ➜

/path/to/project/lib/vendor/Zend/Mail/Message.php

• \Symfony\Core\Request ➜

/path/to/project/lib/vendor/Symfony/Core/Request.php

Thursday, 27 September 12

Page 149: Symfony - Introduction

Lets create our own bundleAcme/Bundle/BlogBundle

Thursday, 27 September 12

Page 150: Symfony - Introduction

./app/config/parameters.ymlGenerate the new bundle

Thursday, 27 September 12

Page 151: Symfony - Introduction

./app/config/parameters.ymlGenerate the new bundle

Thursday, 27 September 12

Page 152: Symfony - Introduction

The modelLets create our Doctrine entity

Thursday, 27 September 12

Page 153: Symfony - Introduction

./app/config/parameters.ymlGenerate the new entity

Thursday, 27 September 12

Page 154: Symfony - Introduction

The CRUD logicLets create our Controller

Thursday, 27 September 12

Page 155: Symfony - Introduction

./app/config/parameters.ymlGenerate the new entity

Thursday, 27 September 12

Page 156: Symfony - Introduction

2 Errors

Thursday, 27 September 12

Page 157: Symfony - Introduction

Oh snap: part 1

Thursday, 27 September 12

Page 158: Symfony - Introduction

./app/config/parameters.yml will fix this

Thursday, 27 September 12

Page 159: Symfony - Introduction

Oh snap: part 2

Thursday, 27 September 12

Page 160: Symfony - Introduction

Update the databaseThere’s a task for that.

Thursday, 27 September 12

Page 161: Symfony - Introduction

./app/config/parameters.ymlGenerate the update query

Thursday, 27 September 12

Page 162: Symfony - Introduction

Looks good, sort of?

Thursday, 27 September 12

Page 163: Symfony - Introduction

Cleaning up

Thursday, 27 September 12

Page 164: Symfony - Introduction

Cleaning up

• Add our new layout template (apply it to views)

Thursday, 27 September 12

Page 165: Symfony - Introduction

Cleaning up

• Add our new layout template (apply it to views)

• Add some CSS (quick look at asset linking)

Thursday, 27 September 12

Page 166: Symfony - Introduction

Cleaning up

• Add our new layout template (apply it to views)

• Add some CSS (quick look at asset linking)

• Discover Assetic (images, css, javascript etc…)

Thursday, 27 September 12

Page 167: Symfony - Introduction

./app/config/parameters.ymlLets use this simple template

Thursday, 27 September 12

Page 168: Symfony - Introduction

./app/config/parameters.ymlAnd apply it to our templates

Thursday, 27 September 12

Page 169: Symfony - Introduction

Why this?{{ asset('bundles/acmeblog/css/demo.css') }}

Thursday, 27 September 12

Page 170: Symfony - Introduction

Why this?{{ asset('bundles/acmeblog/css/demo.css') }}

• Can prefix different paths (dev vs prod)

Thursday, 27 September 12

Page 171: Symfony - Introduction

Why this?{{ asset('bundles/acmeblog/css/demo.css') }}

• Can prefix different paths (dev vs prod)

• Can be used for cache busting (v1, v2, v3, etc…)

Thursday, 27 September 12

Page 172: Symfony - Introduction

./app/config/parameters.yml./app/config/config.yml

Thursday, 27 September 12

Page 173: Symfony - Introduction

Assetic is the next step

Thursday, 27 September 12

Page 174: Symfony - Introduction

Assetic is the next step

• Advanced filters:

Thursday, 27 September 12

Page 175: Symfony - Introduction

Assetic is the next step

• Advanced filters:

• Images (jpegoptim, optipng)

Thursday, 27 September 12

Page 176: Symfony - Introduction

Assetic is the next step

• Advanced filters:

• Images (jpegoptim, optipng)

• CSS (combine and compress)

Thursday, 27 September 12

Page 177: Symfony - Introduction

Assetic is the next step

• Advanced filters:

• Images (jpegoptim, optipng)

• CSS (combine and compress)

• JS (combine and compress)

Thursday, 27 September 12

Page 178: Symfony - Introduction

Assetic is the next step

• Advanced filters:

• Images (jpegoptim, optipng)

• CSS (combine and compress)

• JS (combine and compress)

• LESS, SASS (compile, combine, compress)

Thursday, 27 September 12

Page 179: Symfony - Introduction

./app/config/parameters.ymlUpdate the layout…

Thursday, 27 September 12

Page 180: Symfony - Introduction

Forms & Validation

Thursday, 27 September 12

Page 181: Symfony - Introduction

Forms Widgets

Thursday, 27 September 12

Page 182: Symfony - Introduction

./app/config/parameters.ymlSimple, elegant presentation

Thursday, 27 September 12

Page 183: Symfony - Introduction

Constraints & Assertions

Thursday, 27 September 12

Page 184: Symfony - Introduction

./app/config/parameters.ymlAssertions in annotations

Thursday, 27 September 12

Page 185: Symfony - Introduction

Services

Thursday, 27 September 12

Page 186: Symfony - Introduction

Lets improve Postwho’s setting the “created_at” property?

Thursday, 27 September 12

Page 187: Symfony - Introduction

./app/config/parameters.ymlIn the model?

Thursday, 27 September 12

Page 188: Symfony - Introduction

./app/config/parameters.ymlOn the object?

Thursday, 27 September 12

Page 189: Symfony - Introduction

Maybe there’s a better way?

Thursday, 27 September 12

Page 190: Symfony - Introduction

./app/config/parameters.ymlServices are global toolkits

Thursday, 27 September 12

Page 191: Symfony - Introduction

Service ContainersDependancy Injection

Thursday, 27 September 12

Page 192: Symfony - Introduction

“Dependency injection is a software design pattern that allows a choice of component to be made at run-time rather than

compile time. This can be used, for example, as a simple way to load plugins dynamically or to choose mock objects in test

environments vs. real objects in production environments.”Wikipedia

Thursday, 27 September 12

Page 193: Symfony - Introduction

Finishing up

Thursday, 27 September 12

Page 194: Symfony - Introduction

Finishing up

• Security (broad topic, demo app has an example)

Thursday, 27 September 12

Page 195: Symfony - Introduction

Finishing up

• Security (broad topic, demo app has an example)

• Firewalls (protect areas of application via routes)

Thursday, 27 September 12

Page 196: Symfony - Introduction

Finishing up

• Security (broad topic, demo app has an example)

• Firewalls (protect areas of application via routes)

• Authentication providers (in memory, HTTP, build you own, FOSUserBundle)

Thursday, 27 September 12

Page 197: Symfony - Introduction

Finishing up

• Security (broad topic, demo app has an example)

• Firewalls (protect areas of application via routes)

• Authentication providers (in memory, HTTP, build you own, FOSUserBundle)

• Authorisation (ACL in config or DB)

Thursday, 27 September 12

Page 198: Symfony - Introduction

Out of time…Thursday, 27 September 12

Page 199: Symfony - Introduction

A huge thanks to…

• SensioLabs: t-shirts, pizza, support

• SydPHP: organisation, support

Thursday, 27 September 12

Page 200: Symfony - Introduction

Slides will be up on Speaker Deck shortly…

@warmers

Thursday, 27 September 12