Introduction to Symfony2 - NYPHP

20
INTRODUCTION TO SYMFONY2 Juozas Kaziukėnas // juokaz.com // @juokaz

description

 

Transcript of Introduction to Symfony2 - NYPHP

Page 1: Introduction to Symfony2 - NYPHP

INTRODUCTION TO

SYMFONY2Juozas Kaziukėnas // juokaz.com // @juokaz

Page 2: Introduction to Symfony2 - NYPHP

Juozas Kaziukėnas, Lithuanian

You can call me Joe

More info http://juokaz.com

Page 3: Introduction to Symfony2 - NYPHP

WHAT A FRAMEWORK SHOULD DO?

Page 4: Introduction to Symfony2 - NYPHP

WHAT A FRAMEWORK SHOULD DO?

•Out of the box functionality• Routing• Security• Best practices• Standardization•Development speed• etc.

Page 5: Introduction to Symfony2 - NYPHP

WHAT IS SYMFONY2?

Page 6: Introduction to Symfony2 - NYPHP

WHAT IS SYMFONY2?

• A successor of symfony 1.X• Rewritten from scratch• Turns requests to responses, that’s it• Heavily utilizes PHP 5.3+ features• Component oriented architecture• Supported by Sensio Labs agency, run by Fabien Potencier

Page 7: Introduction to Symfony2 - NYPHP

COMPONENTS

• Building blocks for the framework

• Like: HTTP kernel, Form, Validation, Security, Event dispatcher, Config, Console, etc.

• Independent self-contained components

• Can be used without using Symfony2 as a web framework

Page 8: Introduction to Symfony2 - NYPHP

WHAT SYMFONY2 DOES WELL?

Page 9: Introduction to Symfony2 - NYPHP

WHAT SYMFONY2 DOES WELL?

• Components• Inspired Composer to be created• Silex vs Symfony2 vs your own• Fully working standard distribution• Service container for dependencies

Page 10: Introduction to Symfony2 - NYPHP

SILEX

require_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 11: Introduction to Symfony2 - NYPHP

COMPOSER

• 3rd party dependency management

•Makes life so much easier

• Allows not to have 3rd party checked in into a master repo

• Project-specific dependencies vs PEAR-like system-wide

•One file composer.json to manage all expectations

• Became a de facto standard in PHP projects

Page 12: Introduction to Symfony2 - NYPHP

STARTING WITH SYMFONY2

Page 13: Introduction to Symfony2 - NYPHP

STARTING WITH SYMFONY2

composer.phar create-project symfony/framework-standard-edition path/to/install 2.1.x-dev

php ./app/console server:run

Browse http://localhost:8000/app_dev.php

Page 14: Introduction to Symfony2 - NYPHP

BUNDLES

• “Modules” to separate application code

• Contains controllers, models, templates, etc.

• Symfony framework itself is a bundle called FrameworkBundle

• Repository of available bundles http://knpbundles.com/

• Can be extended to customize

Page 15: Introduction to Symfony2 - NYPHP

BUNDLES

// src/Acme/DemoBundle/Controller/WelcomeController.php

namespace Acme\DemoBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class WelcomeController extends Controller{ public function indexAction() { return $this->render('AcmeDemoBundle:Welcome:index.html.twig'); }}

Page 16: Introduction to Symfony2 - NYPHP

SERVICE CONTAINER

// app/config/config.ymlservices: my_mailer: class: Acme\HelloBundle\Mailer arguments: [sendmail]

class WelcomeController extends Controller{ public function sendEmailAction() { $mailer = $this->get('my_mailer'); $mailer->send('[email protected]', ...); }}

Page 17: Introduction to Symfony2 - NYPHP

COMMUNITY

Page 18: Introduction to Symfony2 - NYPHP

COMMUNITY

• Symfony2 on Twitter• Conferences, user groups• All of this?• Good market to be a developer• Less bugs, active GitHub•Drupal

Page 19: Introduction to Symfony2 - NYPHP

QUESTIONS?

Page 20: Introduction to Symfony2 - NYPHP

THANKS!Juozas Kaziukėnas

@juokaz