LoneStarPHP Symfony2, Its Play Time

Preview:

Citation preview

Symfony2: It’s Play Time

@geoffreytranwww.linkedin.com/in/geoffreytran

IAMA

– Software Engineer at RAPP–Working with PHP since 2005– Co-Founded #zftalk & #zftalk.dev– Dormant Zend Framework Contributor• Zend_Application• Zend_Navigation• Zend_Paginator• Zend_View_Helper_BaseUrl

What is Symfony2?

It simply solves your difficult redundant problems… and gets out of your way

You are not boxed in…

… easy to get started, yet powerful and flexible for advanced users

Pre Zend_Application BootstrapIndex.php

Post Zend_Application

Index.php

“The core architecture is now stable…”

– Fabien Potencier

http://symfony.com/blog/symfony2-final-version-we-are-not-there-yet

In development since December 2009

A lot can happen in a year

A baby?

THE NEXT BIEBER?

A new job?

Top 2% of projects on Ohloh

325 Bundles Publishedhttp://symfony2bundles.org/

What exactly is a bundle?

A bundle is like a plugin… except Symfony2 itself is made up of bundles

“I was using the same idea by organizing my code in [zend framework] modules, but this is really painful”

-- tawfekov via StackOverflow

http://stackoverflow.com/questions/5053369/do-you-think-zend-framework-misses-the-symfonys-bundle-principle

Nothing like Symfony1

Less Magicconfig_autoload.yml.php

Explicit Configurationapp/AppKernel.php

Doctrine2Doctrine2: User.php

Doctrine 1.2: User.php

Decoupled design

What makes up Symfony2?

Configuration

Kernel Directory Structure

Symfony Framework Bundles

Symfony Components

Getting started with Symfony2 distributions

Similar to Linux distributions

http://symfony.com/download

# cd ~/Projects/LoneStarPHP# tar xvzf /path/to/Symfony_Standard_Vendors_2.0.0BETA4.tgz

Extract to your web directory

Check requirements

http://yourhost/LoneStarPHP/web/config.php

Not accessing from localhost? Remove the security check from:web/config.phpweb/app_dev.php

Check requirements

http://yourhost/LoneStarPHP/web/config.php

Check requirements

http://yourhost/LoneStarPHP/web/config.php

Check requirements

http://yourhost/LoneStarPHP/web/config.php

Check requirements

http://yourhost/LoneStarPHP/web/config.php

Configure the database connection

http://yourhost/LoneStarPHP/web/app_dev.php/_configurator/step/0

You can write your own configuration files instead

Yay, Welcome to Symfony!

http://yourhost/LoneStarPHP/web/app_dev.php

What makes a page?

/hello/world

A Route/hello/{name}

A ControllerA PHP function

A Response“<h1>Hello World!</h1>”

Step 1: Create a route

/hello/world

File: app/config/routing.yml

* Routing can also be defined with XML, PHP and as annotations

AcmeDemoBundle:LoneStar:hello maps to

Acme\DemoBundle\Controller\LoneStar::helloAction()

Step 2: Create a controller

/hello/world

File: src/Acme/DemoBundle/Controller/LoneStarController.php

* At its simplest, a controller is just a function

Step 2: Create a controller

/hello/world

File: src/Acme/DemoBundle/Controller/LoneStarController.php

File: app/config/routing.yml

/hello/world

http://yourhost/LoneStarPHP/web/app_dev.php/hello/world

Great… But HTML in controllers? &@*$%!

Meet Twig

http://www.twig-project.org

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

src/Acme/DemoBundle/Controller/LoneStarController.php

Hello World!

http://yourhost/LoneStarPHP/web/app_dev.php/hello/world

Digging Deeper

http://yourhost/LoneStarPHP/web/app_dev.php/hello/world

Digging Deeper

http://yourhost/LoneStarPHP/web/app_dev.php/hello/world

Do less work/hello/world

File: src/Acme/DemoBundle/Controller/LoneStarController.php

Give it a try…