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.
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.
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
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
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
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
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
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
Zend_View • Zend_Viewclass separates presentation code from the application logic and data. • View Scripts • View Helpers http://kb.vteamslabs.com
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
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
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
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
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
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
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
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