Diese Präsentation wurde erfolgreich gemeldet.
Die SlideShare-Präsentation wird heruntergeladen. ×

Simplify your professional web development with symfony

Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Nächste SlideShare
Maemo Development Platform
Maemo Development Platform
Wird geladen in …3
×

Hier ansehen

1 von 40 Anzeige
Anzeige

Weitere Verwandte Inhalte

Diashows für Sie (20)

Anzeige

Ähnlich wie Simplify your professional web development with symfony (20)

Anzeige

Aktuellste (20)

Simplify your professional web development with symfony

  1. 1. symfony Simplify your professional web development with PHP Francois Zaninotto http://www.symfony-project.com/ http://www.sensio.com/
  2. 2. Professional
  3. 3. Professional <ul><li>Heavyweight, complex </li></ul><ul><li>Very expensive </li></ul><ul><li>Full Featured </li></ul><ul><li>Performant </li></ul><ul><li>Extensible </li></ul><ul><li>Documented </li></ul><ul><li>Supported </li></ul><ul><li>Configurable </li></ul><ul><li>Stable </li></ul><ul><li>Easy to use </li></ul><ul><li>Java Struts </li></ul><ul><li>Microsoft .Net </li></ul><ul><li>Symfony </li></ul>
  4. 4. PHP for professionals <ul><li>Stable </li></ul><ul><li>Performant </li></ul><ul><li>Documentation </li></ul><ul><li>Object-oriented (as of PHP5) </li></ul><ul><li>Cheap and efficient Hosts </li></ul><ul><li>Support </li></ul><ul><li>Libraries </li></ul><ul><li>Developers for hire </li></ul><ul><li>Easy </li></ul><ul><li>Cheap </li></ul><ul><li>Large Community </li></ul>
  5. 5. PHP for professionals <ul><li>Stable </li></ul><ul><li>Performant </li></ul><ul><li>Documentation </li></ul><ul><li>Object-oriented (as of PHP5) </li></ul><ul><li>Cheap and efficient Hosts </li></ul><ul><li>Support </li></ul><ul><li>Libraries </li></ul><ul><li>Developers for hire </li></ul><ul><li>Easy </li></ul><ul><li>Cheap </li></ul><ul><li>Large Community </li></ul>Bad reputation Spaghetti code Amateur coding Reinventing the wheel BC breaks Inconsistent syntax Bloated … PHP4
  6. 6. Develop faster <ul><li>Each line of code has a cost </li></ul><ul><ul><li>To write the line </li></ul></ul><ul><ul><li>To test it </li></ul></ul><ul><ul><li>To maintain it </li></ul></ul><ul><li>Write less code </li></ul><ul><ul><li>Architecture : contr o ller, ORM, … </li></ul></ul><ul><ul><li>Configuration </li></ul></ul><ul><ul><li>Autoloading </li></ul></ul><ul><ul><li>Generators </li></ul></ul><ul><ul><li>Helpers </li></ul></ul><ul><li>More time for business rules, edge cases, … </li></ul>less code  less complexity  less bugs  more productivity  more time
  7. 7. Don’t reinvent the wheel <ul><li>Follow best practices </li></ul><ul><li>Object orientation </li></ul><ul><li>MVC Pattern : Model / View / Contr oller </li></ul><ul><li>Object-Relational Mapping / Active Record </li></ul><ul><li>Unit and functional tests </li></ul><ul><li>Agile development </li></ul>simplify your life
  8. 8. Professionals need more than PHP alone <ul><li>a PHP framework? </li></ul>
  9. 9. Professionals need more than PHP alone <ul><li>a PHP framework? </li></ul>
  10. 10. Many of them lack… <ul><li>Tests </li></ul><ul><li>Stability </li></ul><ul><li>Support </li></ul><ul><li>Security </li></ul><ul><li>Examples </li></ul><ul><li>Liberal license </li></ul><ul><li>Documentation </li></ul><ul><li>Critical user mass </li></ul><ul><li>Multi-platformness </li></ul><ul><li>DB engines support </li></ul><ul><li>Not suitable for professionals </li></ul>
  11. 11. Sensio <ul><li>French Web Agency </li></ul><ul><li>Founded 9 years ago </li></ul><ul><li>200 web projects </li></ul><ul><li>30 people </li></ul><ul><li>Faith in open-source </li></ul><ul><li>Demanding clients </li></ul><ul><li>Objectives: Have fun </li></ul><ul><ul><ul><ul><ul><li>Make money </li></ul></ul></ul></ul></ul>Webmarketing Open Source Technologies (Framework PHP) Web Technologies SENSIO Web Agency
  12. 12. The challenge <ul><li>Bring together </li></ul><ul><li>the Enterprise world </li></ul><ul><li>and the Open-Source world </li></ul>
  13. 13. symfony <ul><li>PHP 5 Web Framework </li></ul><ul><li>Based on 9 years of Sensio experience </li></ul><ul><li>Based on well-known projets (Mojavi, Propel, Prado) </li></ul><ul><li>Open-Source </li></ul><ul><li>Built for : </li></ul><ul><ul><li>Professional Websites </li></ul></ul><ul><ul><li>Complex needs </li></ul></ul><ul><ul><li>Demanding environments </li></ul></ul>Licence MIT Bring together Entreprise World Open-Source World
  14. 14. What makes the difference <ul><li>Documentation </li></ul><ul><li>Configurability </li></ul><ul><li>XSS protection </li></ul><ul><li>Debugging tools </li></ul><ul><li>Functional tests </li></ul><ul><li>Extensibility : Plugins </li></ul><ul><li>Admin Generator </li></ul><ul><li>ORM : Propel or Doctrine </li></ul><ul><li>i18n / l10n </li></ul><ul><li>1.0 maintained for a long time </li></ul>Standard PHP 5 MVC Routing Cache
  15. 15. Installation is a breeze <ul><li>PEAR </li></ul><ul><li>$ pear channel-discover pear.symfony-project.com </li></ul><ul><li>$ pear install symfony/symfony-1.0.0 </li></ul><ul><li>SVN / symlink </li></ul><ul><li>$ svn propedit svn:externals </li></ul><ul><li>symfony http://svn.symfony-project.com/branches/1.0 </li></ul><ul><li>Sandbox </li></ul><ul><li>$ curl -O http://www.symfony-project.com/get/sf_sandbox-1.0.0.tgz </li></ul><ul><li>$ tar zxpf sf_sandbox-1.0.0.tgz </li></ul>easy fast recommended
  16. 16. Directory structure generation <ul><li>$ mkdir ~/sfdemo </li></ul><ul><li>$ cd ~/sfdemo </li></ul><ul><li>$ symfony init-project sfdemo </li></ul><ul><li>$ ./symfony init-app frontend </li></ul>Project  Application(s)  Module(s)  Action(s) Composant(s)  Template
  17. 18. Database connection settings <ul><li># config/databases.yml </li></ul><ul><li>prod : </li></ul><ul><li>propel: </li></ul><ul><li>param: </li></ul><ul><li>password: PAssWD </li></ul><ul><li>all : </li></ul><ul><li>propel: </li></ul><ul><li>class: sfPropelDatabase </li></ul><ul><li>param: </li></ul><ul><li>dsn: mysql://root:@localhost/sfdemo </li></ul>Environment support
  18. 19. Database schema definition <ul><li># config/schema.yml </li></ul><ul><ul><li>post: </li></ul></ul><ul><ul><li>title: { type: varchar, size: 255 } </li></ul></ul><ul><ul><li>content: { type: longvarchar } </li></ul></ul><ul><ul><li>is_published: { type: boolean } </li></ul></ul><ul><ul><li>author_id: { type: integer, foreignTable: author , </li></ul></ul><ul><ul><li>foreignReference: id } </li></ul></ul><ul><ul><li>created_at: ~ </li></ul></ul>SQL abstraction
  19. 20. Test data <ul><li># data/fixtures/data.yml </li></ul><ul><li>Author: </li></ul><ul><li>fabien : </li></ul><ul><li>first_name: Fabien </li></ul><ul><li>last_name: Potencier </li></ul><ul><li>Post: </li></ul><ul><li>first_post: </li></ul><ul><li>author_id: fabien </li></ul><ul><li>title: Xtech 2007 </li></ul>
  20. 21. Generate the thing <ul><li>$ ./symfony propel-build-all-load frontend </li></ul>1) Creates model classes 2) Converts schema to SQL 3) Creates tables 4) Loads test data
  21. 22. Model <ul><li>// lib/model/Author.php </li></ul><ul><li>class Author extends BaseAuthor </li></ul><ul><li>{ </li></ul><ul><li>function getFullName() </li></ul><ul><li>{ </li></ul><ul><li>return $this -> getFirstName(). ' ' .$this -> getLastName(); </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>$author = new Author(); </li></ul><ul><li>$author -> setFirstName( 'Fabien' ); </li></ul><ul><li>$author -> setLastName( 'Potencier' ); </li></ul><ul><li>$author -> save(); </li></ul><ul><li>$post = new Post(); </li></ul><ul><li>$post -> setAuthor($author); </li></ul><ul><li>$post -> setPublishedOn( '12:00 tomorrow' ); </li></ul><ul><li>$post -> isPublished( true ); </li></ul><ul><li>$post -> save(); </li></ul><ul><li>$posts = PostPeer :: doSelect(new Criteria()); </li></ul>ORM Object Relationship Mapping Propel / Doctrine
  22. 23. Backend creation <ul><li>Automatic creation of an Administration Backend, ready for production </li></ul><ul><ul><li>Lists </li></ul></ul><ul><ul><li>Pagination </li></ul></ul><ul><ul><li>Sorting </li></ul></ul><ul><li>$ ./symfony propel-init-admin frontend post Post </li></ul><ul><ul><li>Filters </li></ul></ul><ul><ul><li>Validation </li></ul></ul><ul><ul><li>CRUD </li></ul></ul>1) Creates a post module 2) Generates configuration Generated code is MVC and customizable Configuration file Contr oller Templates
  23. 24. Configurability <ul><li>Module level </li></ul><ul><li># apps/frontend/modules/post/config/generator.yml </li></ul><ul><li>generator: </li></ul><ul><li>class: sfPropelAdminGenerator </li></ul><ul><li>param: </li></ul><ul><li>model_class: Post </li></ul><ul><li>list : </li></ul><ul><li>display: [ =title , author, created_at] </li></ul><ul><li>filters : [title, author_id, published_on] </li></ul><ul><li>max_per_page: 5 </li></ul><ul><li>Application level </li></ul><ul><li># apps/frontend/config/security.yml </li></ul><ul><li>default: </li></ul><ul><li>is_secure: on </li></ul><ul><li>credentials: admin </li></ul><ul><li>$ ./symfony plugin-install http://plugins.symfony-project.com/ sfGuardPlugin </li></ul>Configuration Framework Project Application Module LOC : 0
  24. 25. Admin Generator – list view
  25. 26. Admin Generator – edit view __toString() widgets m2m relationship
  26. 27. Extensibility <ul><li>Module extension </li></ul><ul><li>class postActions extends autoPostActions </li></ul><ul><li>{ </li></ul><ul><li>protected function addFiltersCriteria($c) </li></ul><ul><li>{ </li></ul><ul><li>parent :: addFiltersCriteria($c); </li></ul><ul><li>$c -> add(PostPeer :: IS_PUBLISHED, true ); </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>Template customization </li></ul>Generated module _edit_* : actions, footer, form, header, messages _list_* : footer, header, messages, td_actions, t(d|h)_stacked, t(d|h)_tabular _filters, editSuccess, listSuccess
  27. 28. Frontend Creation <ul><li>Routing </li></ul><?php echo link_to( $post -> getTitle(), '@post?id=’ .$post -> getId() ) ?> post : param: { module: blog, action: show } requirements: id: + url: /blog/:id.html <?php echo url_for( '@homepage' ) ?> homepage : param: { module: blog, action: recent } url: / homepage : param: { module: blog, action: list } url: / recent : param: { module: blog, action: recent } url: /recent /blog/1.html / / /recent
  28. 29. Functional Tests <ul><li>Simulate navigation and make smart assertions </li></ul><ul><li>// test/functional/frontend/blogActionsTest.php </li></ul><ul><li>$browser = new sfTestBrowser(); </li></ul><ul><li>$browser -> initialize(); </li></ul><ul><li>$browser -> </li></ul><ul><li>get( '/blog/1.html' ) -> </li></ul><ul><li>isStatusCode( 200 ) -> </li></ul><ul><li>checkResponseElement( 'h1.title' , '/XTech 2007/' ); </li></ul><ul><ul><li>$ ./symfony test-functional frontend </li></ul></ul><ul><ul><li># get / </li></ul></ul><ul><ul><li>ok 1 - status code is 200 </li></ul></ul><ul><ul><li>not ok 2 - response selector h1 does not match regex /XTech 2007/ </li></ul></ul><ul><ul><li># Looks like you failed 1 tests of 2 </li></ul></ul><ul><ul><li>1..2 </li></ul></ul>TDD Test Driven Development CSS Selector
  29. 30. Our first line of code <ul><li># apps/frontend/modules/blog/actions/actions.class.php </li></ul><ul><li>class blogActions extends sfActions </li></ul><ul><li>{ </li></ul><ul><li>function executeShow() </li></ul><ul><li>{ </li></ul><ul><li>$id = $this -> getRequestParameter( 'id' ); </li></ul><ul><li>$this -> post = PostPeer :: retrieveByPk($id); </li></ul><ul><li>$this -> forward404Unless($this -> post); </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li># apps/frontend/modules/post/templates/showSuccess.php </li></ul><ul><li><h1 class= &quot;title&quot; ><?php echo $post -> getTitle() ?></h1> </li></ul><ul><li><h2>par <?php echo $post -> getAuthor() -> getFullName() ?></h2> </li></ul><ul><li><p><?php echo $post -> getHtmlContent(ESC_RAW) ?></p> </li></ul>MVC Model / View / Contr oller XSS Secure by default shortcut
  30. 31. Debugging tools – The web debug toolbar
  31. 32. Debugging tools – Meaningful error messages
  32. 33. Deployment <ul><li>$ ./symfony test-all </li></ul><ul><li>functional/frontend/postActionsTest...................... ok </li></ul><ul><li>All tests successful. </li></ul><ul><li>Files=1, Tests=2 </li></ul><ul><li># config/properties.ini </li></ul><ul><li>[production] </li></ul><ul><li>host= 1.2.3.4 </li></ul><ul><li>user= fabien </li></ul><ul><li>dir= /var/www/sfblog </li></ul><ul><li>type= rsync </li></ul><ul><li>$ ./symfony sync production go </li></ul>$ ./symfony freeze
  33. 34. Once it is in production <ul><li>Optimized for speed and stability </li></ul><ul><li>Internals never shown </li></ul><ul><li>Logs rotation </li></ul><ul><li>Data dumping </li></ul><ul><li>404/500 error logging </li></ul><ul><li>Incremental updates (via rsync) </li></ul>
  34. 35. Community Plugins <ul><li>Hooks in the symfony code allow for easy extension </li></ul><ul><li>New plugins are created every week </li></ul><ul><ul><li>Doctrine : Full Doctrine ORM support </li></ul></ul><ul><ul><li>UJS : Unobtrusive JavaScript </li></ul></ul><ul><ul><li>PropelActAsNestedSetBehavior : Nested sets for Propel </li></ul></ul><ul><ul><li>PropelActAsTaggableBehavior : Easy tags for Propel </li></ul></ul><ul><ul><li>SuperCache : HTML pages cache </li></ul></ul><ul><ul><li>ControlPanel : Web management for symfony projects </li></ul></ul><ul><ul><li>ErrorLogger : All 404 and 500 logging in a table </li></ul></ul><ul><ul><li>Guard : Authentication and authorization features </li></ul></ul><ul><ul><li>Feed2 : Web feeds management (read&write) </li></ul></ul><ul><ul><li>PokaYoke : Client side validation </li></ul></ul>
  35. 36. A Professional Web Framework <ul><li>Built from experience </li></ul><ul><li>Clean, modular and customizable code </li></ul><ul><li>1.0 stable, maintained with commercial support </li></ul><ul><li>Growing community </li></ul><ul><ul><li>Developpers in more than 80 countries </li></ul></ul><ul><ul><li>100 000 visitors per month on symfony-project.com </li></ul></ul><ul><li>Open-Source Documentation </li></ul><ul><ul><li>The book (450 pages - GFDL) </li></ul></ul><ul><ul><li>Askeet Tutorial (250 pages) </li></ul></ul>
  36. 37. Do you need a second opinion? <ul><li>Yahoo! (USA) </li></ul><ul><li>Yahoo! Bookmarks </li></ul><ul><li>20 millions users </li></ul><ul><li>Web 2.0 / AJAX </li></ul>
  37. 38. What’s next? <ul><li>Forge : www.symfony-forge.com </li></ul><ul><li>New features for symfony 1.1 </li></ul><ul><ul><li>More hooks for plugins </li></ul></ul><ul><ul><li>More modularity </li></ul></ul><ul><ul><li>Official Doctrine support </li></ul></ul><ul><ul><li>Unobstrusive JavaScript support </li></ul></ul><ul><ul><li>New form and validation framework </li></ul></ul><ul><li>Book translation </li></ul>中文 , Deutsch, Español, Français Polski, Russian, 日本語 , Italiano, …
  38. 39. How to make money with open-source? <ul><li>Sensio Labs provides symfony-focused services </li></ul><ul><ul><li>Training </li></ul></ul><ul><ul><li>Code auditing </li></ul></ul><ul><ul><li>Consulting </li></ul></ul><ul><ul><li>Web development </li></ul></ul><ul><li>If you are looking for a job in France, we're hiring </li></ul>
  39. 40. <ul><li>SENSIO S.A. </li></ul><ul><li>26, rue Salomon de Rothschild </li></ul><ul><li>92 286 SURESNES cedex </li></ul><ul><li>FRANCE </li></ul><ul><li>Tél. : +33 1 40 99 80 80 </li></ul><ul><li>Fax : +33 1 40 99 83 34 </li></ul><ul><li>Contact </li></ul><ul><li>Francois Zaninotto </li></ul><ul><li>http://www.sensio.com/ http://www.symfony-project.com/ </li></ul>

Hinweis der Redaktion

  • I&apos;m François Zaninotto, manager at Sensio Labs, co-author of sf and main author of sf doc today’s presentation : how to simplify your professional web development with symfony why we created symfony 3 years ago. main selling points of symfony. features that makes symfony a good framework for your next project.

×