SlideShare una empresa de Scribd logo
1 de 33
Descargar para leer sin conexión
symfony
   in action.


     WebTech 2007
symfony ?




• PHP 5 Web Framework

• Based on well-known projets   (Mojavi, Propel, Prado …)


• Open-Source (MIT licence)

• Sponsored by Sensio ( http://www.sensio.com/ )
cite from symfony book




If you have been looking for a Rails/Django-like
   framework for PHP projects with features such as:

·   simple templating and helpers
·   cache management
·   multiple environments support
·   deployment management
·   scaffolding
·   smart URLs
·   multilingual and I18N support
·   object model and MVC separation
·   Ajax support

...where all elements work seamlessly together, then
   symfony is made for you
don’t reinvent the wheel




• Follow best practices

• MVC Pattern : Model / View / Controller

• Unit and functional test framework

• Environment and deployment support

• Security (XSS protection)

• Extensible (plugin system)
a professional web framework




• Built from experience
• 1.0 stable, maintained with commercial
  support
• Growing community
  – Developpers in more than 80 countries
  – 100 000 visitors per month on
    symfony-project.com
• Open-Source Documentation
  – The book (450 pages - GFDL)
  – Askeet Tutorial (250 pages)
Sounds good ?
 Let’s try it !
requirements




• PHP5

• Web server (Apache)

• RDBMS (MySQL)
installation




• Sandbox
> wget http://www.symfony-project.com/get/sf_sandbox.tgz

• PEAR
> pear channel-discover pear.symfony-project.com
> pear install symfony/symfony


• Subversion
> svn checkout http://svn.symfony-project.com/branches/1.0/
  .
init new symfony project




                                            Project

                                         Application(s)
> mkdir WebTechComments
> cd WebTechComments
                                           Module(s)


> symfony init-project WebTechComments
                                          Actions(s)
> symfony init-app frontend
                                         Composant(s)


                                           Template
web server configuration




<VirtualHost *:80>

  ServerName WebTechComments
  DocumentRoot quot;/path/to/project/webquot;
  DirectoryIndex index.php

  Alias /sf /path/to/symfony/data/symfony/web/sf

  <Directory quot;/path/to/project/webquot;>
    AllowOverride All
  </Directory>

</VirtualHost>
demo




        Congratulations!

You have successfully created your
         symfony project.
object-relational mapping



• Tables as classes and records as objects
    public function getName()
    {
      return $this->getFirstName.' '.$this->getLastName();
                                                                        Relational      Object-Oriented
    }


                                                                        Table           Class
    public function getTotal()
                                                                        Row, record     Object
    {
      $total = 0;
                                                                        Field, column   Property
         foreach ($this->getItems() as $item)
        {
           $total += $item->getPrice() * $item->getQuantity();
        }
 
        return $total;
    }


• Object and Peer classes
    $article = new Article();
    ...
    $title = $article->getTitle();


    $articles = ArticlePeer::retrieveByPks(array(123, 124, 125));
create database schema



#/config/schema.yml
  propel:
    sessions:
     _attributes: { phpName: Session }
     id:
     date: timestamp
     speaker: varchar(255)
     topic: varchar(255)
     description: longvarchar
    comments:
     _attributes: { phpName: Comment }
     id:
     sessions_id:
       type: integer
       foreignTable: sessions
       foreignReference: id
       onDelete: cascade
       phpName: SessionId
       peerName: SESSION_ID
     author: varchar(255)
     content: longvarchar
     created_at:
build model and database




• Configuration
    – database access
    – Propel properties

•   Build model           > symfony propel-build-model
•   Build SQL             > symfony propel-build-sql
•   Create database       > symfony propel-insert-sql
•   Do them all           > symfony propel-build-all
define some test data




• Test data
# data/fixtures/data.yml
Session:
                                > symfony propel-load-data   frontend
 s1:
  date: 06/29/2007
  speaker: Test Speaker
  topic: Test Topic
  description: Just for testing
Comment:
 c1:
  sessions_id: s1
  author: Teo Tester
  content: It’s better when other do the tests
scafolding




• Create / Retrieval / Update / Delete (CRUD)

• Initiating or Generating Code
> symfony <TASK_NAME> <APP_NAME> <MODULE_NAME> <CLASS_NAME>
tasks: propel-init-crud, propel-generate-crud, and propel-init-admin




 > symfony propel-generate-crud frontend session Session
 > symfony propel-init-crud frontend comment Comment
routing




homepage:
                                                                       Internal URI
 url: /
                                                     <module>/<action>[?param1=value1][&param2=value2]
 param: { module: session, action: list }

<?php echo url_for(‘@homepage’) ?> => /
                                                                      External URL
                                                     http://www.example.com/module/action/[param1/value1]
session_view:
 url: /session/:id.html
 param: { module: session, action: view }
 requirements:
   id: d+

<?php echo link_to(‘@sesion_view?id=’.$session->getId()) ?> => /session/12.html


default:
 url: /:module/:action/*

<?php echo url_for(‘session/view?id=’.$session->getId()) ?>   => /session/view/id/12
view




• Templates
• Helpers
• Page layout
• Code fragments
  – Partials
  – Components
  – Slots
view



                   <h1>Welcome</h1>

• Templates        <p>Welcome back, <?php echo $name ?>!</p>
                   <p>What would you like to do?</p>
                   <ul>
• Helpers           <li><?php echo link_to('Read', 'article/read') ?></li>
                    <li><?php echo link_to(‘Write', 'article/write') ?></li>
• Page layout      </ul>


• Code fragments
  – Partials
  – Components
  – Slots
view



                 <?php echo use_helper('HelperName') ?>
                 <?php echo use_helper('HelperName1', 'HelperName2' ) ?>
• Templates
                 <?php echo tag('input', array('name' => 'foo', 'type' => 'text')) ?>
• Helpers        <?php echo tag('input', 'name =foo type=text') ?>
                 => <input name=quot;fooquot; type=quot;textquot; />

• Page layout
• Code fragments
  – Partials
  – Components
  – Slots
view




• Templates
• Helpers
• Page layout
• Code fragments
  – Partials
  – Components
  – Slots
view




• Templates
• Helpers
• Page layout
• Code fragments
  – Partials
  – Components
  – Slots
view




• Templates
• Helpers
• Page layout
• Code fragments
  – Partials
  – Components
  – Slots
view




• Templates
• Helpers
• Page layout
• Code fragments
  – Partials
  – Components
  – Slots
controller




• Front controller

• Actions

• Request

• User sessions
• Validation
• Filters
controller



                     1 Define the core constants.

• Front controller   2 Locate the symfony libraries.
                     3 Load and initiate the core framework classes.

• Actions            4 Load the configuration.
                     5 Decode the request URL to determine the action to
                     execute and the request parameters.

• Request            6 If the action does not exist, redirect to the 404 error
                     action.
                     7 Activate filters (for instance, if the request needs
• User sessions      authentication).
                     8 Execute the filters, first pass.

• Validation         9 Execute the action and render the view.
                     10 Execute the filters, second pass.

• Filters            11# Output the response
controller

                     class mymoduleActions extends sfActions
                     {
                         public function executeIndex()
                         {
• Front controller           // Retrieving request parameters
                             $password = $this->getRequestParameter('password');


• Actions                    // Retrieving controller information
                             $moduleName = $this->getModuleName();
                             $actionName = $this->getActionName();  
• Request                    // Retrieving framework core objects
                             $request = $this->getRequest();

• User sessions              $userSession = $this->getUser();
                             $response = $this->getResponse();


• Validation           // Setting action variables to pass information to the
                     template
                             $this->setVar('foo', 'bar');

• Filters                    $this->foo = 'bar'; // Shorter version  
                         }
                     }
controller


                     $this->getRequest()->

                     getMethod() sfRequest::GET sfRequest::POST

• Front controller   getCookie('foo')
                     isXmlHttpRequest()
                     isSecure()

• Actions            hasParameter('foo')
                     getParameter('foo')

• Request            getParameterHolder()->getAll()

                     getLanguages()

• User sessions      getAcceptableContentTypes()

                     getFileNames()

• Validation         getFileSize($fileName)
                     getFileType($fileName)


• Filters            setAttribute(‘foo’)
                     getAttribute(‘foo’)
controller



                     $this->getUser()->

• Front controller
                     setAttribute('nickname', $nickname)

• Actions            getAttribute('nickname', ‘Default')


                     getAttributeHolder()->remove('nickname')
• Request            getAttributeHolder()->clear()


• User sessions
                     $this->setFlash('attrib', $value)

• Validation         $this->getFlash('attrib')



• Filters
controller


                     class myModuleActions extends sfActions
                     {
                         public function validateMyAction()
• Front controller       {
                             return ($this->getRequestParameter('id') > 0);
                         }
• Actions
                         public function handleErrorMyAction()
                         {
• Request                    $this->message = quot;Invalid parametersquot;;

                             return sfView::SUCCESS;
• User sessions          }

                         public function executeMyAction()
• Validation             {
                             $this->message = quot;The parameters are correctquot;;
                         }
• Filters            }
controller




• Front controller

• Actions

• Request

• User sessions
• Validation
• Filters
Live demo !
Questions ?



   Петър Вукадинов (patter)
   p.vukadinov@pi-consult.bg
      p.vukadinov@gmail.com

Más contenido relacionado

La actualidad más candente

Rich Model And Layered Architecture in SF2 Application
Rich Model And Layered Architecture in SF2 ApplicationRich Model And Layered Architecture in SF2 Application
Rich Model And Layered Architecture in SF2 ApplicationKirill Chebunin
 
SPL: The Missing Link in Development
SPL: The Missing Link in DevelopmentSPL: The Missing Link in Development
SPL: The Missing Link in Developmentjsmith92
 
Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)Kris Wallsmith
 
Silex meets SOAP & REST
Silex meets SOAP & RESTSilex meets SOAP & REST
Silex meets SOAP & RESTHugo Hamon
 
Introducing Assetic: Asset Management for PHP 5.3
Introducing Assetic: Asset Management for PHP 5.3Introducing Assetic: Asset Management for PHP 5.3
Introducing Assetic: Asset Management for PHP 5.3Kris Wallsmith
 
Phpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friendsPhpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friendsMichael Peacock
 
Beyond symfony 1.2 (Symfony Camp 2008)
Beyond symfony 1.2 (Symfony Camp 2008)Beyond symfony 1.2 (Symfony Camp 2008)
Beyond symfony 1.2 (Symfony Camp 2008)Fabien Potencier
 
Dependency Injection in PHP
Dependency Injection in PHPDependency Injection in PHP
Dependency Injection in PHPKacper Gunia
 
sfDay Cologne - Sonata Admin Bundle
sfDay Cologne - Sonata Admin BundlesfDay Cologne - Sonata Admin Bundle
sfDay Cologne - Sonata Admin Bundleth0masr
 
Dirty Secrets of the PHP SOAP Extension
Dirty Secrets of the PHP SOAP ExtensionDirty Secrets of the PHP SOAP Extension
Dirty Secrets of the PHP SOAP ExtensionAdam Trachtenberg
 
A Little Backbone For Your App
A Little Backbone For Your AppA Little Backbone For Your App
A Little Backbone For Your AppLuca Mearelli
 
Crud operations using aws dynamo db with flask ap is and boto3
Crud operations using aws dynamo db with flask ap is and boto3Crud operations using aws dynamo db with flask ap is and boto3
Crud operations using aws dynamo db with flask ap is and boto3Katy Slemon
 
Electrify your code with PHP Generators
Electrify your code with PHP GeneratorsElectrify your code with PHP Generators
Electrify your code with PHP GeneratorsMark Baker
 
Things Your Mother Didn't Tell You About Bundle Configurations - Symfony Live...
Things Your Mother Didn't Tell You About Bundle Configurations - Symfony Live...Things Your Mother Didn't Tell You About Bundle Configurations - Symfony Live...
Things Your Mother Didn't Tell You About Bundle Configurations - Symfony Live...D
 
Things Your Mother Didnt Tell You About Bundle Configurations - Symfony Live…
Things Your Mother Didnt Tell You About Bundle Configurations - Symfony Live…Things Your Mother Didnt Tell You About Bundle Configurations - Symfony Live…
Things Your Mother Didnt Tell You About Bundle Configurations - Symfony Live…D
 
Forget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers CracowForget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers CracowKacper Gunia
 

La actualidad más candente (20)

Rich Model And Layered Architecture in SF2 Application
Rich Model And Layered Architecture in SF2 ApplicationRich Model And Layered Architecture in SF2 Application
Rich Model And Layered Architecture in SF2 Application
 
SPL: The Missing Link in Development
SPL: The Missing Link in DevelopmentSPL: The Missing Link in Development
SPL: The Missing Link in Development
 
Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)
 
CodeIgniter 3.0
CodeIgniter 3.0CodeIgniter 3.0
CodeIgniter 3.0
 
Silex meets SOAP & REST
Silex meets SOAP & RESTSilex meets SOAP & REST
Silex meets SOAP & REST
 
Introducing Assetic: Asset Management for PHP 5.3
Introducing Assetic: Asset Management for PHP 5.3Introducing Assetic: Asset Management for PHP 5.3
Introducing Assetic: Asset Management for PHP 5.3
 
Phpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friendsPhpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friends
 
Fatc
FatcFatc
Fatc
 
Zero to SOLID
Zero to SOLIDZero to SOLID
Zero to SOLID
 
Beyond symfony 1.2 (Symfony Camp 2008)
Beyond symfony 1.2 (Symfony Camp 2008)Beyond symfony 1.2 (Symfony Camp 2008)
Beyond symfony 1.2 (Symfony Camp 2008)
 
Dependency Injection in PHP
Dependency Injection in PHPDependency Injection in PHP
Dependency Injection in PHP
 
sfDay Cologne - Sonata Admin Bundle
sfDay Cologne - Sonata Admin BundlesfDay Cologne - Sonata Admin Bundle
sfDay Cologne - Sonata Admin Bundle
 
Dirty Secrets of the PHP SOAP Extension
Dirty Secrets of the PHP SOAP ExtensionDirty Secrets of the PHP SOAP Extension
Dirty Secrets of the PHP SOAP Extension
 
Silex Cheat Sheet
Silex Cheat SheetSilex Cheat Sheet
Silex Cheat Sheet
 
A Little Backbone For Your App
A Little Backbone For Your AppA Little Backbone For Your App
A Little Backbone For Your App
 
Crud operations using aws dynamo db with flask ap is and boto3
Crud operations using aws dynamo db with flask ap is and boto3Crud operations using aws dynamo db with flask ap is and boto3
Crud operations using aws dynamo db with flask ap is and boto3
 
Electrify your code with PHP Generators
Electrify your code with PHP GeneratorsElectrify your code with PHP Generators
Electrify your code with PHP Generators
 
Things Your Mother Didn't Tell You About Bundle Configurations - Symfony Live...
Things Your Mother Didn't Tell You About Bundle Configurations - Symfony Live...Things Your Mother Didn't Tell You About Bundle Configurations - Symfony Live...
Things Your Mother Didn't Tell You About Bundle Configurations - Symfony Live...
 
Things Your Mother Didnt Tell You About Bundle Configurations - Symfony Live…
Things Your Mother Didnt Tell You About Bundle Configurations - Symfony Live…Things Your Mother Didnt Tell You About Bundle Configurations - Symfony Live…
Things Your Mother Didnt Tell You About Bundle Configurations - Symfony Live…
 
Forget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers CracowForget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers Cracow
 

Similar a Symfony in Action: A PHP 5 Web Framework

関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐいHisateru Tanaka
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5Darren Craig
 
Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2Hugo Hamon
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Michelangelo van Dam
 
Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Michelangelo van Dam
 
From CakePHP to Laravel
From CakePHP to LaravelFrom CakePHP to Laravel
From CakePHP to LaravelJason McCreary
 
Magento Live Australia 2016: Request Flow
Magento Live Australia 2016: Request FlowMagento Live Australia 2016: Request Flow
Magento Live Australia 2016: Request FlowVrann Tulika
 
Building Testable PHP Applications
Building Testable PHP ApplicationsBuilding Testable PHP Applications
Building Testable PHP Applicationschartjes
 
Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Michelangelo van Dam
 
Symfony2 from the Trenches
Symfony2 from the TrenchesSymfony2 from the Trenches
Symfony2 from the TrenchesJonathan Wage
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenchesLukas Smith
 
The Solar Framework for PHP 5 (2010 Confoo)
The Solar Framework for PHP 5 (2010 Confoo)The Solar Framework for PHP 5 (2010 Confoo)
The Solar Framework for PHP 5 (2010 Confoo)Paul Jones
 
All I Need to Know I Learned by Writing My Own Web Framework
All I Need to Know I Learned by Writing My Own Web FrameworkAll I Need to Know I Learned by Writing My Own Web Framework
All I Need to Know I Learned by Writing My Own Web FrameworkBen Scofield
 
CodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkCodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkBo-Yi Wu
 
Lean Php Presentation
Lean Php PresentationLean Php Presentation
Lean Php PresentationAlan Pinstein
 
Mojolicious - A new hope
Mojolicious - A new hopeMojolicious - A new hope
Mojolicious - A new hopeMarcus Ramberg
 
Symfony components in the wild, PHPNW12
Symfony components in the wild, PHPNW12Symfony components in the wild, PHPNW12
Symfony components in the wild, PHPNW12Jakub Zalas
 
Simplify your professional web development with symfony
Simplify your professional web development with symfonySimplify your professional web development with symfony
Simplify your professional web development with symfonyFrancois Zaninotto
 
Symfony CMF - PHP Conference Brazil 2011
Symfony CMF - PHP Conference Brazil 2011Symfony CMF - PHP Conference Brazil 2011
Symfony CMF - PHP Conference Brazil 2011Jacopo Romei
 

Similar a Symfony in Action: A PHP 5 Web Framework (20)

関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5
 
Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12
 
Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8
 
Symfony2 revealed
Symfony2 revealedSymfony2 revealed
Symfony2 revealed
 
From CakePHP to Laravel
From CakePHP to LaravelFrom CakePHP to Laravel
From CakePHP to Laravel
 
Magento Live Australia 2016: Request Flow
Magento Live Australia 2016: Request FlowMagento Live Australia 2016: Request Flow
Magento Live Australia 2016: Request Flow
 
Building Testable PHP Applications
Building Testable PHP ApplicationsBuilding Testable PHP Applications
Building Testable PHP Applications
 
Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012
 
Symfony2 from the Trenches
Symfony2 from the TrenchesSymfony2 from the Trenches
Symfony2 from the Trenches
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenches
 
The Solar Framework for PHP 5 (2010 Confoo)
The Solar Framework for PHP 5 (2010 Confoo)The Solar Framework for PHP 5 (2010 Confoo)
The Solar Framework for PHP 5 (2010 Confoo)
 
All I Need to Know I Learned by Writing My Own Web Framework
All I Need to Know I Learned by Writing My Own Web FrameworkAll I Need to Know I Learned by Writing My Own Web Framework
All I Need to Know I Learned by Writing My Own Web Framework
 
CodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkCodeIgniter PHP MVC Framework
CodeIgniter PHP MVC Framework
 
Lean Php Presentation
Lean Php PresentationLean Php Presentation
Lean Php Presentation
 
Mojolicious - A new hope
Mojolicious - A new hopeMojolicious - A new hope
Mojolicious - A new hope
 
Symfony components in the wild, PHPNW12
Symfony components in the wild, PHPNW12Symfony components in the wild, PHPNW12
Symfony components in the wild, PHPNW12
 
Simplify your professional web development with symfony
Simplify your professional web development with symfonySimplify your professional web development with symfony
Simplify your professional web development with symfony
 
Symfony CMF - PHP Conference Brazil 2011
Symfony CMF - PHP Conference Brazil 2011Symfony CMF - PHP Conference Brazil 2011
Symfony CMF - PHP Conference Brazil 2011
 

Último

Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...BookNet Canada
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
Digital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentDigital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentMahmoud Rabie
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Nikki Chapple
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Mark Simos
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sectoritnewsafrica
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...itnewsafrica
 
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...itnewsafrica
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
Kuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialKuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialJoão Esperancinha
 

Último (20)

Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
Digital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentDigital Tools & AI in Career Development
Digital Tools & AI in Career Development
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
 
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
Kuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialKuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorial
 

Symfony in Action: A PHP 5 Web Framework

  • 1. symfony in action. WebTech 2007
  • 2. symfony ? • PHP 5 Web Framework • Based on well-known projets (Mojavi, Propel, Prado …) • Open-Source (MIT licence) • Sponsored by Sensio ( http://www.sensio.com/ )
  • 3. cite from symfony book If you have been looking for a Rails/Django-like framework for PHP projects with features such as: · simple templating and helpers · cache management · multiple environments support · deployment management · scaffolding · smart URLs · multilingual and I18N support · object model and MVC separation · Ajax support ...where all elements work seamlessly together, then symfony is made for you
  • 4. don’t reinvent the wheel • Follow best practices • MVC Pattern : Model / View / Controller • Unit and functional test framework • Environment and deployment support • Security (XSS protection) • Extensible (plugin system)
  • 5. a professional web framework • Built from experience • 1.0 stable, maintained with commercial support • Growing community – Developpers in more than 80 countries – 100 000 visitors per month on symfony-project.com • Open-Source Documentation – The book (450 pages - GFDL) – Askeet Tutorial (250 pages)
  • 6. Sounds good ? Let’s try it !
  • 7. requirements • PHP5 • Web server (Apache) • RDBMS (MySQL)
  • 8. installation • Sandbox > wget http://www.symfony-project.com/get/sf_sandbox.tgz • PEAR > pear channel-discover pear.symfony-project.com > pear install symfony/symfony • Subversion > svn checkout http://svn.symfony-project.com/branches/1.0/ .
  • 9. init new symfony project Project Application(s) > mkdir WebTechComments > cd WebTechComments Module(s) > symfony init-project WebTechComments Actions(s) > symfony init-app frontend Composant(s) Template
  • 10. web server configuration <VirtualHost *:80> ServerName WebTechComments DocumentRoot quot;/path/to/project/webquot; DirectoryIndex index.php Alias /sf /path/to/symfony/data/symfony/web/sf <Directory quot;/path/to/project/webquot;> AllowOverride All </Directory> </VirtualHost>
  • 11. demo Congratulations! You have successfully created your symfony project.
  • 12. object-relational mapping • Tables as classes and records as objects public function getName() { return $this->getFirstName.' '.$this->getLastName(); Relational Object-Oriented } Table Class public function getTotal() Row, record Object { $total = 0; Field, column Property foreach ($this->getItems() as $item) { $total += $item->getPrice() * $item->getQuantity(); }   return $total; } • Object and Peer classes $article = new Article(); ... $title = $article->getTitle(); $articles = ArticlePeer::retrieveByPks(array(123, 124, 125));
  • 13. create database schema #/config/schema.yml propel: sessions: _attributes: { phpName: Session } id: date: timestamp speaker: varchar(255) topic: varchar(255) description: longvarchar comments: _attributes: { phpName: Comment } id: sessions_id: type: integer foreignTable: sessions foreignReference: id onDelete: cascade phpName: SessionId peerName: SESSION_ID author: varchar(255) content: longvarchar created_at:
  • 14. build model and database • Configuration – database access – Propel properties • Build model > symfony propel-build-model • Build SQL > symfony propel-build-sql • Create database > symfony propel-insert-sql • Do them all > symfony propel-build-all
  • 15. define some test data • Test data # data/fixtures/data.yml Session: > symfony propel-load-data frontend s1: date: 06/29/2007 speaker: Test Speaker topic: Test Topic description: Just for testing Comment: c1: sessions_id: s1 author: Teo Tester content: It’s better when other do the tests
  • 16. scafolding • Create / Retrieval / Update / Delete (CRUD) • Initiating or Generating Code > symfony <TASK_NAME> <APP_NAME> <MODULE_NAME> <CLASS_NAME> tasks: propel-init-crud, propel-generate-crud, and propel-init-admin > symfony propel-generate-crud frontend session Session > symfony propel-init-crud frontend comment Comment
  • 17. routing homepage: Internal URI url: / <module>/<action>[?param1=value1][&param2=value2] param: { module: session, action: list } <?php echo url_for(‘@homepage’) ?> => / External URL http://www.example.com/module/action/[param1/value1] session_view: url: /session/:id.html param: { module: session, action: view } requirements: id: d+ <?php echo link_to(‘@sesion_view?id=’.$session->getId()) ?> => /session/12.html default: url: /:module/:action/* <?php echo url_for(‘session/view?id=’.$session->getId()) ?> => /session/view/id/12
  • 18. view • Templates • Helpers • Page layout • Code fragments – Partials – Components – Slots
  • 19. view <h1>Welcome</h1> • Templates <p>Welcome back, <?php echo $name ?>!</p> <p>What would you like to do?</p> <ul> • Helpers <li><?php echo link_to('Read', 'article/read') ?></li> <li><?php echo link_to(‘Write', 'article/write') ?></li> • Page layout </ul> • Code fragments – Partials – Components – Slots
  • 20. view <?php echo use_helper('HelperName') ?> <?php echo use_helper('HelperName1', 'HelperName2' ) ?> • Templates <?php echo tag('input', array('name' => 'foo', 'type' => 'text')) ?> • Helpers <?php echo tag('input', 'name =foo type=text') ?> => <input name=quot;fooquot; type=quot;textquot; /> • Page layout • Code fragments – Partials – Components – Slots
  • 21. view • Templates • Helpers • Page layout • Code fragments – Partials – Components – Slots
  • 22. view • Templates • Helpers • Page layout • Code fragments – Partials – Components – Slots
  • 23. view • Templates • Helpers • Page layout • Code fragments – Partials – Components – Slots
  • 24. view • Templates • Helpers • Page layout • Code fragments – Partials – Components – Slots
  • 25. controller • Front controller • Actions • Request • User sessions • Validation • Filters
  • 26. controller 1 Define the core constants. • Front controller 2 Locate the symfony libraries. 3 Load and initiate the core framework classes. • Actions 4 Load the configuration. 5 Decode the request URL to determine the action to execute and the request parameters. • Request 6 If the action does not exist, redirect to the 404 error action. 7 Activate filters (for instance, if the request needs • User sessions authentication). 8 Execute the filters, first pass. • Validation 9 Execute the action and render the view. 10 Execute the filters, second pass. • Filters 11# Output the response
  • 27. controller class mymoduleActions extends sfActions { public function executeIndex() { • Front controller // Retrieving request parameters $password = $this->getRequestParameter('password'); • Actions // Retrieving controller information $moduleName = $this->getModuleName(); $actionName = $this->getActionName();   • Request // Retrieving framework core objects $request = $this->getRequest(); • User sessions $userSession = $this->getUser(); $response = $this->getResponse(); • Validation // Setting action variables to pass information to the template $this->setVar('foo', 'bar'); • Filters $this->foo = 'bar'; // Shorter version   } }
  • 28. controller $this->getRequest()-> getMethod() sfRequest::GET sfRequest::POST • Front controller getCookie('foo') isXmlHttpRequest() isSecure() • Actions hasParameter('foo') getParameter('foo') • Request getParameterHolder()->getAll() getLanguages() • User sessions getAcceptableContentTypes() getFileNames() • Validation getFileSize($fileName) getFileType($fileName) • Filters setAttribute(‘foo’) getAttribute(‘foo’)
  • 29. controller $this->getUser()-> • Front controller setAttribute('nickname', $nickname) • Actions getAttribute('nickname', ‘Default') getAttributeHolder()->remove('nickname') • Request getAttributeHolder()->clear() • User sessions $this->setFlash('attrib', $value) • Validation $this->getFlash('attrib') • Filters
  • 30. controller class myModuleActions extends sfActions { public function validateMyAction() • Front controller { return ($this->getRequestParameter('id') > 0); } • Actions public function handleErrorMyAction() { • Request $this->message = quot;Invalid parametersquot;; return sfView::SUCCESS; • User sessions } public function executeMyAction() • Validation { $this->message = quot;The parameters are correctquot;; } • Filters }
  • 31. controller • Front controller • Actions • Request • User sessions • Validation • Filters
  • 33. Questions ? Петър Вукадинов (patter) p.vukadinov@pi-consult.bg p.vukadinov@gmail.com