1 / 59

ZEND FRAMEWORK Basics Training

ZEND FRAMEWORK Basics Training. By: Raza Mehdi. Topics Covered in Session. What is Zend Framework? What is Model-View-Controller Pattern? Coding Guidelines for Zend Framework. Difference between Zend Framework versions.

ovidio
Download Presentation

ZEND FRAMEWORK Basics Training

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ZEND FRAMEWORK Basics Training • By: Raza Mehdi http://kb.vteamslabs.com

  2. Topics Covered in Session • What is Zend Framework? • What is Model-View-Controller Pattern? • Coding Guidelines for Zend Framework. • Difference between Zend Framework versions. • Development of a simple Application using Zend Framework to showcase its various features. http://kb.vteamslabs.com

  3. What Is Zend Framework? • Zend Framework (ZF) is an open source, object-oriented web application development framework implemented in PHP5 and licensed under the New BSD License. • This framework is designed to eliminate the tedious process of developing a codebase for a specific system as much as possible. • This framework implements the highly-modular MVCdesign, making your code more reusable and easier to maintain. http://kb.vteamslabs.com

  4. Defining Model-View-Controller http://kb.vteamslabs.com

  5. Model http://kb.vteamslabs.com

  6. VIEW http://kb.vteamslabs.com

  7. CONTROLLER http://kb.vteamslabs.com

  8. CODING GUIDELINES FOR ZEND FRAMEWORK • No leading or trailing spaces. • Proper namespace like Zend_ etc. For Resources like forms and models Form_ & Model_namespace is ideal. • Use camel-style lowercase instead of underscores (as in getTodaysDate()) for function names. • Use underscore in start for your variables if they are private or protected. • Declare all variables as private, protected, or public. • Use standard php tag <?php ?>. • Use spaces when concatenating text for making code more readable. • Use pass-by reference in function declaration. http://kb.vteamslabs.com

  9. Zend Framework Versions • Zend Framework is available in two versions: • ZF 1.11 contains support for older PHP versions like 5.2 etc. • ZF2 is based on PHP version 5.3+, and is the framework’s latest release. This training session will utilize ZF 1.11 as reference in the coming slides. http://kb.vteamslabs.com

  10. DIFFERENCES BETWEEN ZF1 & ZF2 http://kb.vteamslabs.com

  11. DIFFERENCES BETWEEN ZF1 & ZF2 (Continued …) http://kb.vteamslabs.com

  12. ZEND FRAMEWORK APPLICATION DEVELOPMENT http://kb.vteamslabs.com

  13. Sample Bugs Reporting System • Installation & Configuration of Zend Framework • Capturing the data: The data is captured, validated, and filtered by Zend_Form. • Storing the data: The data to be stored in the database by using Zend_Db. http://kb.vteamslabs.com

  14. Installation & Configuration of Zend Framework • Download latest ZF1 release from http://framework.zend.com/downloads/latest#ZF1 • Extract the folder to your desired location. • Copy the contents of bin folder to PHP installation directory. • Copy the contents of library folder to PHP’s include path. • Environment Variable PATH = “C:/xampp/php” • Open Command Line, and enter command: zfcreate project PROJECT_NAME http://kb.vteamslabs.com

  15. http://kb.vteamslabs.com

  16. DETAILED LOOK AT ZF PROJECT FILES http://kb.vteamslabs.com

  17. .htaccess in /public folder http://kb.vteamslabs.com

  18. Index.php in /public folder http://kb.vteamslabs.com

  19. /application/configs/application.ini http://kb.vteamslabs.com

  20. Adding Layouts using Zend_View, Zend_Layout http://kb.vteamslabs.com

  21. Zend_View • Zend_Viewclass separates presentation code from the application logic and data. • View Scripts • View Helpers http://kb.vteamslabs.com

  22. The view scripts are basically PHP files that are rendered within the scope of Zend_View. View Scripts are rendered in two stages: • First, the action controller creates a new instance of Zend_View(done using view renderer action helper), which you load with data in your action method. • Second, once the action method has been processed, the view renderer helper tells Zend_Viewto render the appropriate view script. http://kb.vteamslabs.com

  23. View helpersare simply classes. When you call a helper from within your script: • Zend_Viewcreates a new instance of the class and then runs the method that it relates to the helper class name. • View Helper are named using the camelCaseconvention. For example, MyHelper will run the myHelper() method. • Zend_View then returns the response from the respective method. http://kb.vteamslabs.com

  24. Zend_Layout Zend_Layoutenables you to create templates that wrap your individual view scripts. It can be used: • Standalone component: In this case, Zend_Layout allows you to name sections of your site templates and then load these from within your controller and view scripts. • MVC component: Zend_Layoutis initiated by its startMvcmethod. Normally following parameters are passed in array: • layout: layout script to render. • layoutPath: This is the path to the layout scripts. • contentKey: ‘content’ In the controllers by using: $this->_helper->layout. In the view by using the view helper: $this->layout(). http://kb.vteamslabs.com

  25. Views Structure to be used in ZF http://kb.vteamslabs.com

  26. Creating Layouts • Create a new folder in the application folder named layouts. • Add a subfolder to the layouts folder named scripts. • Create a file called layout.phtml. • Add the following lines to application/configs/application.ini: resources.layout.layoutPath= APPLICATION_PATH "/layouts/scripts/" OR Run this command zf enable layout in the terminal or command prompt in the project directory. You must create css, images sub-folders in the public folder. http://kb.vteamslabs.com

  27. Adding Zend_View’sPlaceholders http://kb.vteamslabs.com

  28. CREATING FORMS USING Zend_Form http://kb.vteamslabs.com

  29. What is Zend_Form? • Zend_Formis a wrapper for XHTML forms, wrapped in <form /> tag. It is constructed & rendered using its native init() & render() methods respectively. • The Zend_Form object serves as a container for Zend_Form_Element objects which contain all of the standard form & form elements attributes. It also supports several non-standard form controls, such as Dojo widgets. • Zend_Form’s XHTML output is handled by decorators. Decorators are snippets of code that render the appropriate markup dynamically, and can be used up-to requirements for any element object. • Custom form elements can be created. http://kb.vteamslabs.com

  30. Create a Form using Zend_Form • Create a folder forms in applications folder. • Create a file BugReport.phpin applications/forms folder. • Create a file BugController.phpin applications/controllers folder. Following fields are to be added: • Author • E-mail • Date • URL • Description • Priority • Status http://kb.vteamslabs.com

  31. Adding Elements to Zend_Form http://kb.vteamslabs.com

  32. Zend_Form Resource Mapping in Bootstrap Edit the application/Bootstrap.phpto add the following code: http://kb.vteamslabs.com

  33. Adding Zend_Form to View http://kb.vteamslabs.com

  34. Adding Zend_Form to View (continued …) http://kb.vteamslabs.com

  35. http://kb.vteamslabs.com

  36. Managing Data USING Zend_Db http://kb.vteamslabs.com

  37. What is Zend_Db? Zend_Db is an object-oriented interface to SQL database systems. Zend Framework uses adapters to connect to database servers. These adapters provide a standardized interface to a range of commercially available database systems, including the following: • IBM DB2 • MySQL • Microsoft SQL Server • Oracle • PostgreSQL • SQLite http://kb.vteamslabs.com

  38. Database Configuration application/configs/application.ini http://kb.vteamslabs.com

  39. Models Resource Mapping in Bootstrap • Edit the _initAutoload function in application/Bootstrap.php as: http://kb.vteamslabs.com

  40. Creating bugs Model http://kb.vteamslabs.com

  41. Creating CRUD for bugs MODEL http://kb.vteamslabs.com

  42. ADDING A RECORD http://kb.vteamslabs.com

  43. 1. Adding a method for data insertion in Model http://kb.vteamslabs.com

  44. 2. Updating the Bug Controller’s Submit Action http://kb.vteamslabs.com

  45. 3. Creating the Confirmation page • Create a method called confirmActionin application/controllers/BugController.phpfile. • Create a view file confirm.phtml in applications/views/scripts/bug/ folder, and add the following code: http://kb.vteamslabs.com

  46. EDITING RECORDS http://kb.vteamslabs.com

  47. 1. Creating method in Model to update records http://kb.vteamslabs.com

  48. 2. Creating the view file for update records • Create a file edit.phtml in the applications/views/scripts/bug/ folder, and add the following code: http://kb.vteamslabs.com

  49. 2. Creating method in Controller to update records http://kb.vteamslabs.com

  50. VIEWING ALL RECORDS http://kb.vteamslabs.com

More Related