Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2...

71
Symfony 101 Introducing Symfony 2 By Kevin Gustavson

Transcript of Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2...

Page 1: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Symfony 101

Introducing Symfony 2By Kevin Gustavson

Page 2: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

@kgustavson● Senior Software Developer at CellTrak● 6 Years of Web Development● Nearly 2 years with Symfony 2.0

Page 3: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Introducing CellTrak VisitManager 2.0

Page 4: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Introducing CellTrak VisitManager 2.0

Page 5: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

CellTrak VisitManager 2.0

Page 6: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Why did CellTrack choose Symfony 2?

Page 7: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Why did CellTrack choose Symfony 2?

Symfony 2 was among the first of a new breed of PHP frameworks.

Page 8: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Why did CellTrack choose Symfony 2?

Symfony 2 was among the first of a new breed of PHP frameworks.

● PHP 5.3

Page 9: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Why did CellTrack choose Symfony 2?

Symfony 2 was among the first of a new breed of PHP frameworks.

● PHP 5.3○ Namespaces

Page 10: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Why did CellTrack choose Symfony 2?

Symfony 2 was among the first of a new breed of PHP frameworks.

● PHP 5.3○ Namespaces○ Standardized Class Loading

Page 11: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Why did CellTrack choose Symfony 2?

Symfony 2 was among the first of a new breed of PHP frameworks.

● PHP 5.3○ Namespaces○ Standardized Class Loading○ Anonymous functions

Page 12: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Why did CellTrack choose Symfony 2?

Symfony 2 was among the first of a new breed of PHP frameworks.

● PHP 5.3○ Namespaces○ Standardized Class Loading○ Anonymous functions○ Closures

Page 13: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Why Did CellTrak Choose Symfony 2? (Cont.)

Page 14: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Why Did CellTrak Choose Symfony 2? (Cont.)

● Symfony 2 was the most advanced framework at the time.

Page 15: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Why Did CellTrak Choose Symfony 2? (Cont.)

● Symfony 2 was the most advanced framework at the time.

● Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time.

Page 16: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Why Did CellTrak Choose Symfony 2? (Cont.)

● Symfony 2 was the most advanced framework at the time.

● Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time.

● Symfony 2 was well documented.

Page 17: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Why Did CellTrak Choose Symfony 2? (Cont.)

● Symfony 2 was the most advanced framework at the time.

● Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time.

● Symfony 2 was well documented.● Symfony's development team and

community are responsive.

Page 18: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Symfony is an MVC Framework.

Page 19: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Symfony is an MVC Framework.

ModelModels, called Entities in Symfony 2, are where your data is stored and managed.

Page 20: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Symfony is an MVC Framework.

ModelModels, called Entities in Symfony 2, are where your data is stored and managed.

ViewViews are document templates. They are intended to be light, data-free and logic-free.

Page 21: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Symfony is an MVC Framework.

ModelModels, called Entities in Symfony 2, are where your data is stored and managed.

ViewViews are document templates. They are intended to be light, data-free and logic-free.(Well, mostly!)

Page 22: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Symfony is an MVC Framework.

ModelModels, called Entities in Symfony 2, are where your data is stored and managed.

ViewViews are document templates. They are intended to be light, data-free and logic-free.(Well, mostly!)

ControllerController actions begin with Request and return a Response. They talk to both the Models and the Views to generate their Response.

Page 23: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Symfony is an MVC Framework.

ModelModels, called Entities in Symfony 2, are where your data is stored and managed.

ViewViews are document templates. They are intended to be light, data-free and logic-free.(Well, mostly!)

ControllerController actions begin with Request and return a Response. They talk to both the Models and the Views to generate their Response.

RoutesTie URLs to controller actions.

Page 24: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Symfony's Core Goals

Page 25: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Symfony's Core Goals

Symfony 1.x started with a specific set of goals...

Page 26: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Symfony's Core Goals

Symfony 1.x started with a specific set of goals...● Loosely coupled components

Page 27: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Symfony's Core Goals

Symfony 1.x started with a specific set of goals...● Loosely coupled components● Predictable conventions

Page 28: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Symfony's Core Goals

Symfony 1.x started with a specific set of goals...● Loosely coupled components● Predictable conventions● Highly configurable (different forms)

Page 29: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Symfony's Core Goals

Symfony 1.x started with a specific set of goals...● Loosely coupled components● Predictable conventions● Highly configurable (different forms)● Testable

Page 30: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Symfony's Core Goals

Symfony 1.x started with a specific set of goals...● Loosely coupled components● Predictable conventions● Highly configurable (different forms)● Testable● Great developer tools

Page 31: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Symfony's Core Goals

Page 32: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Symfony's Core Goals

Symfony2 added to those goals...

Page 33: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Symfony's Core Goals

Symfony2 added to those goals...● PHP 5.3 (Namespaces, closures, interfaces)

Page 34: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Symfony's Core Goals

Symfony2 added to those goals...● PHP 5.3 (Namespaces, closures, interfaces)● Smarter, lazier

Page 35: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Symfony's Core Goals

Symfony2 added to those goals...● PHP 5.3 (Namespaces, closures, interfaces)● Smarter, lazier● Very, very fast

Page 36: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Symfony's Core Goals

Symfony2 added to those goals...● PHP 5.3 (Namespaces, closures, interfaces)● Smarter, lazier● Very, very fast

Although not an explicit goal, everthing in Symfony is Pattern based.

Page 37: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Symfony's Core Goals

Symfony2 added to those goals...● PHP 5.3 (Namespaces, closures, interfaces)● Smarter, lazier● Very, very fast

Although not an explicit goal, everthing in Symfony is Pattern based.

Patterns of Enterprise Application ArchitectureBy Martin Fowler

Page 38: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Doctrine 2 ORM

Page 39: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Doctrine 2 ORM

● Very fast (caching)

Page 40: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Doctrine 2 ORM

● Very fast (caching)● Transactional by design

Page 41: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Doctrine 2 ORM

● Very fast (caching)● Transactional by design● Repositories for business logic

Page 42: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Doctrine 2 ORM

● Very fast (caching)● Transactional by design● Repositories for business logic● Fully relational

Page 43: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Doctrine 2 ORM

● Very fast (caching)● Transactional by design● Repositories for business logic● Fully relational● Uses the Data Mapper pattern

Page 44: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Folder Structure

Page 45: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Folder Structureapp/● Configuration files● Cache● Logs

Page 46: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Folder Structureapp/● Configuration files● Cache● Logs

web/● Front-end Controllers● CSS● Javascript

Page 47: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Folder Structureapp/● Configuration files● Cache● Logs

web/● Front-end Controllers● CSS● Javascript

vendor/● Symfony Bundles, Community Bundles, and other libraries

Page 48: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Folder Structureapp/● Configuration files● Cache● Logs

web/● Front-end Controllers● CSS● Javascript

vendor/● Symfony Bundles, Community Bundles, and other libraries

src/● Your Bundles

Page 49: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Installing Symfony 2

Page 50: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Installing Symfony 2Browse to http://symfony.com/download and download "Symfony Standard 2.2.0 (.zip)"

Page 51: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Installing Symfony 2Browse to http://symfony.com/download and download "Symfony Standard 2.2.0 (.zip)"

$ cd $WORKSPACE

Page 52: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Installing Symfony 2Browse to http://symfony.com/download and download "Symfony Standard 2.2.0 (.zip)"

$ cd $WORKSPACE$ unzip Symfony_Standard_Vendors_2.2.0.zip

Page 53: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Installing Symfony 2Browse to http://symfony.com/download and download "Symfony Standard 2.2.0 (.zip)"

$ cd $WORKSPACE$ unzip Symfony_Standard_Vendors_2.2.0.zip$ cd Symfony/

Page 54: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Installing Symfony 2Browse to http://symfony.com/download and download "Symfony Standard 2.2.0 (.zip)"

$ cd $WORKSPACE$ unzip Symfony_Standard_Vendors_2.2.0.zip$ cd Symfony/$ app/console server:run

Page 55: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Installing Symfony 2Browse to http://symfony.com/download and download "Symfony Standard 2.2.0 (.zip)"

$ cd $WORKSPACE$ unzip Symfony_Standard_Vendors_2.2.0.zip$ cd Symfony/$ app/console server:run

Browse to localhost:8000/

Page 56: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Installing Symfony 2Browse to http://symfony.com/download and download "Symfony Standard 2.2.0 (.zip)"

$ cd $WORKSPACE$ unzip Symfony_Standard_Vendors_2.2.0.zip$ cd Symfony/$ app/console server:run

Browse to localhost:8000/

...and you're live!!

Page 57: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Live Demo!!

Page 58: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Asset Management

Page 59: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Asset ManagementThe Assetic Service

Page 60: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Asset ManagementThe Assetic Service

● Javascript and CSS Compression

Page 61: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Asset ManagementThe Assetic Service:

● Javascript and CSS Compression● Optimized Images

Page 62: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Asset ManagementThe Assetic Service:

● Javascript and CSS Compression● Optimized Images● CSS Preprocessors (SASS or LESS)

Page 63: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Asset ManagementThe Assetic Service:

● Javascript and CSS Compression● Optimized Images● CSS Preprocessors (SASS or LESS)● Javascript Preprocessors (Coffeescript)

Page 64: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Great Developer Tools

Page 65: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Great Developer ToolsGreat Developer Tools is one of Symfony's original design goals.

Page 66: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Great Developer ToolsGreat Developer Tools is one of Symfony's original design goals.

● Command-line tools

Page 67: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Great Developer ToolsGreat Developer Tools is one of Symfony's original design goals.

● Command-line tools● Robust backtrace

Page 68: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Great Developer ToolsGreat Developer Tools is one of Symfony's original design goals.

● Command-line tools● Robust backtrace● ChromePHP and FirePHP

Page 69: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Great Developer ToolsGreat Developer Tools is one of Symfony's original design goals.

● Command-line tools● Robust backtrace● ChromePHP and FirePHP● Web Development Toolbar

Page 70: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Too Much?

Try Silexrequire_once __DIR__.'/../vendor/autoload.php';

$app = new Silex\Application;

$app->get('/hello/{name}', function($name) use($app) { return 'Hello '.$app->escape($name); });

$app->run();

Page 71: Symfony 101 · Symfony 2? (Cont.) Symfony 2 was the most advanced framework at the time. Symfony 2 includes Doctrine 2, which was the most advanced PHP ORM at the time. Symfony 2

Sound Interesting?Symfony.comSilex.SensioLabs.org

CellTrak is looking for web developers of all levels to join our team.

See: www.celltrak.com/about/careers/