Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

symfony on action - WebTech 207

9,478 views

Published on

Published in: Technology, Education
  • These are one of the best companies for review articles. High quality with cheap rates. ⇒⇒⇒WRITE-MY-PAPER.net ⇐⇐⇐ I highly recommend it :)
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Sex in your area is here: ❤❤❤ http://bit.ly/2F7hN3u ❤❤❤
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Dating for everyone is here: ❶❶❶ http://bit.ly/2F7hN3u ❶❶❶
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

symfony on action - WebTech 207

  1. 1. symfony in action. WebTech 2007
  2. 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. 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. 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. 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. 6. Sounds good ? Let’s try it !
  7. 7. requirements • PHP5 • Web server (Apache) • RDBMS (MySQL)
  8. 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. 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. 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. 11. demo Congratulations! You have successfully created your symfony project.
  12. 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. 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. 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. 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. 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. 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. 18. view • Templates • Helpers • Page layout • Code fragments – Partials – Components – Slots
  19. 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. 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. 21. view • Templates • Helpers • Page layout • Code fragments – Partials – Components – Slots
  22. 22. view • Templates • Helpers • Page layout • Code fragments – Partials – Components – Slots
  23. 23. view • Templates • Helpers • Page layout • Code fragments – Partials – Components – Slots
  24. 24. view • Templates • Helpers • Page layout • Code fragments – Partials – Components – Slots
  25. 25. controller • Front controller • Actions • Request • User sessions • Validation • Filters
  26. 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. 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. 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. 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. 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. 31. controller • Front controller • Actions • Request • User sessions • Validation • Filters
  32. 32. Live demo !
  33. 33. Questions ? Петър Вукадинов (patter) p.vukadinov@pi-consult.bg p.vukadinov@gmail.com

×