Successfully reported this slideshow.
Your SlideShare is downloading. ×

Introduction to Zend framework

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad

Check these out next

1 of 25 Ad

More Related Content

Slideshows for you (20)

Similar to Introduction to Zend framework (20)

Advertisement

More from Matteo Magni (20)

Advertisement

Introduction to Zend framework

  1. 1. Zend Framework 1.x $incontro['pugBO'][7] = 'Introduction to Zend Framework' http://magni.me
  2. 2. whoami • Matteo Magni • @ilbonzo • https://github.com/ilbonzo • http://it.linkedin.com/in/matteomagni $incontro['pugBO'][7] = 'Introduction to Zend Framework' http://magni.me
  3. 3. Zend Framework 1.X • Zend Framework is an open source, object oriented web application framework for PHP 5. Zend Framework is often called a 'component library', because it has many loosely coupled components that you can use more or less independently. • http://framework.zend.com/ • BSD license • Version 1.11 $incontro['pugBO'][7] = 'Introduction to Zend Framework' http://magni.me
  4. 4. Installation • Register and download source • Add to your include path – sudo mv ~/ZendFramework­1.11.11/library/Zend/  /usr/share/php/Zend OR – sudo mv ~/ZendFramework­1.11.11/library/Zend/  [project]/library/Zend • Install bin tools – sudo mv ~/ZendFramework­1.11.11  /usr/share/php/ZendFramework – alias zf=/usr/share/php/ZendFramework/bin/zf.sh $incontro['pugBO'][7] = 'Introduction to Zend Framework' http://magni.me
  5. 5. MVC $incontro['pugBO'][7] = 'Introduction to Zend Framework' http://magni.me
  6. 6. Demo project for Layar • http://layar.com/ It's mobile browser allows users to find various items based upon augmented reality technology. • https://github.com/ilbonzo/Wade $incontro['pugBO'][7] = 'Introduction to Zend Framework' http://magni.me
  7. 7. Create Project $incontro['pugBO'][7] = 'Introduction to Zend Framework' http://magni.me
  8. 8. Config Apps /application/configs/application.ini $incontro['pugBO'][7] = 'Introduction to Zend Framework' http://magni.me
  9. 9. Bootstrap /application/Bootstrap.php class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {     protected function _initDoctype()     {         $this­>bootstrap('view');         $view = $this­>getResource('view');         $view­>doctype('HTML5');     }     ....... } $incontro['pugBO'][7] = 'Introduction to Zend Framework' http://magni.me
  10. 10. Layouts • $ zf enable layout  • /application/configs/application.ini – resources.layout.layoutPath = APPLICATION_PATH  "/layouts/scripts/" • Twitter Bootstrap http://twitter.github.com/bootstrap/ Other Layouts $this­>_helper­>layout­>setLayout('layout_other'); $incontro['pugBO'][7] = 'Introduction to Zend Framework' http://magni.me
  11. 11. ZF overview • Models(db- tables,objectmodels) • Views(helpers,scripts,layouts) • Controllers(actions,helpers) • Forms $incontro['pugBO'][7] = 'Introduction to Zend Framework' http://magni.me
  12. 12. Namespace & Route • All classes named for their folder (e.g.Application_Model_Post in application/models/post.php) • Every Zend module is auto loaded when needed • Default controller/action is Index • URLformat: /<controller>/<action> $incontro['pugBO'][7] = 'Introduction to Zend Framework' http://magni.me
  13. 13. Controller & Actions $ zf create controller Point $ zf create action view Point $ zf create action add Point $ zf create action update Point $ zf create action delete Point create file /application/controllers/PointController.php class PointController extends Zend_Controller_Action {     public function init()     {         /* Initialize action controller here */     }     public function indexAction()    {        // action body    } $incontro['pugBO'][7] = 'Introduction to Zend Framework'  ... http://magni.me
  14. 14. Views e Actions • Create views /application/views/scripts/point/[action].phtml esempio: <br /><br /> <div id="view­content"> <p>View script for controller <b>Point</b> and  script/action name <b>add</b></p> </div> $incontro['pugBO'][7] = 'Introduction to Zend Framework' http://magni.me
  15. 15. Database /application/configs/application.ini PostgreSQL DB resources.db.adapter = PDO_PGSQL resources.db.params.host = localhost resources.db.params.username = postgres resources.db.params.password =  resources.db.params.dbname = wade $incontro['pugBO'][7] = 'Introduction to Zend Framework' http://magni.me
  16. 16. Zend_Db The Zend_Db_Table solution is an implementation of the Table Data Gateway pattern. The solution also includes a class that implements the Row Data Gateway pattern. $incontro['pugBO'][7] = 'Introduction to Zend Framework' http://magni.me
  17. 17. DbTable - DbTableRow $ zf create db­table Points points $ zf create model Point /application/models/Point.php class Application_Model_Point extends Zend_Db_Table_Row_Abstract {     function __get($key)     {         if (method_exists($this, $key)) {             return $this­>$key();         }         return parent::__get($key);     } } $incontro['pugBO'][7] = 'Introduction to Zend Framework' http://magni.me
  18. 18. Form - Validation $ zf create form Point /application/forms/Point.php class Application_Form_Point extends Zend_Form {     public function init()     {         $title = new Zend_Form_Element_Text('title');         $title­>setLabel('title')                 ­>setRequired(true)                 ­>addFilter('StripTags')                 ­>addFilter('StringTrim')                 ­>addValidator('NotEmpty');     } } $incontro['pugBO'][7] = 'Introduction to Zend Framework' http://magni.me
  19. 19. Controller – Form /application/controllers/PointController.php         $form = new Application_Form_Point();         $form­>submit­>setLabel('Add');         $this­>view­>form = $form;         if ($this­>getRequest()­>isPost()) {             $formData = $this­>getRequest()­>getPost();             if ($form­>isValid($formData)) {                 $title = $form­>getValue('title');                 ....                 $point = new Application_Model_DbTable_Points();                 $point­>addPoint($title, $footnote, $description, $lat, $lon,  $alt);                 $this­>_helper­>redirector('index');             } else {                 $form­>populate($formData);             }         }         $incontro['pugBO'][7] = 'Introduction to Zend Framework' http://magni.me
  20. 20. Views - Form /application/views/scripts/point/add.phtml <?php $this­>title = "Add new Point"; $this­>headTitle($this­>title); echo $this­>form ; ?> $incontro['pugBO'][7] = 'Introduction to Zend Framework' http://magni.me
  21. 21. Models and Table Relationships class Application_Model_DbTable_Points extends Zend_Db_Table_Abstract {       protected $_dependentTables = array('Application_Model_DbTable_Actions'); .... class Application_Model_DbTable_Actions extends Zend_Db_Table_Abstract {     protected $_name = 'actions';     protected $_rowClass = 'Application_Model_Action';     protected $_primary = 'id';          protected $_referenceMap = array(         'Application_Model_DbTable_Points' => array(          'columns' => array('point_id'),             'refTableClass' => 'Application_Model_DbTable_Points',             'refColumns' => array('id')         ), $incontro['pugBO'][7] = 'Introduction to Zend Framework' http://magni.me
  22. 22. Component Library Zend_Acl • Zend_Amf • Zend_Application • Zend_Auth • Zend_Barcode • Zend_Cache • Zend_Captcha • -------- • Zend_Config • Zend_Config_Writer • Zend_Controller • Zend_Currency • Zend_Date • Zend_Db • ---------- • ZendX_JQuery • $incontro['pugBO'][7] = 'Introduction to Zend Framework' http://magni.me
  23. 23. Youtube https://developers.google.com/youtube/2.0/developers_guide_php $incontro['pugBO'][7] = 'Introduction to Zend Framework' http://magni.me
  24. 24. ZF & Drupal http://drupal.org/project/zend It's possible but Dries chose Symfony $incontro['pugBO'][7] = 'Introduction to Zend Framework' http://magni.me
  25. 25. Questions? http://blog.ilbonzo.org http://twitter.com/ilbonzo $incontro['pugBO'][7] = 'Introduction to Zend Framework' http://magni.me

×