1 / 82

ZEND FRAMEWORK Advanced Training

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

rigg
Download Presentation

ZEND FRAMEWORK Advanced 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 Advanced Training • By: Raza Mehdi http://kb.vteamslabs.com

  2. Topics Covered in Previous 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. TOPICS FOR SESSION • Themes using Zend_Layout & Zend_View • Zend_Pagination • Managing Table Relationships using Zend_Db • Handling Security in Zend Framework. • Site Search Using Zend_Search_Lucene. • Modules in Zend Framework. http://kb.vteamslabs.com

  4. THEMES Using Zend_Layout & Zend_View http://kb.vteamslabs.com

  5. 1. Layout & Views Folders http://kb.vteamslabs.com

  6. 2. Changed Layout & Views Folders for Themes http://kb.vteamslabs.com

  7. 3. Change Bootstrap.php to load Themes • Add a constructor function to load theme of choice: http://kb.vteamslabs.com

  8. 3. Change Bootstrap.php to load Themes (cont ..) • Add a _initLayout function to load layout files of selected theme: http://kb.vteamslabs.com

  9. 3. Change Bootstrap.php to load Themes (cont ..) • Add a _initView function to load view files of selected theme: http://kb.vteamslabs.com

  10. 4. Create Theme Configuration File • The template.xml in each theme folder may hold theme config information as well as theme’s CSS & JS filenames. For example: http://kb.vteamslabs.com

  11. 5. Create View Helper To Load Theme Config Create a file called LoadTemplate.phpin application/views/helpers folder to load information from template.xml. http://kb.vteamslabs.com

  12. 5.1 Loading Theme Config Data http://kb.vteamslabs.com

  13. 5.2 Saving Configuration Data • Next we will save the retrieved configuration data as array. http://kb.vteamslabs.com

  14. 5.3 Adding Configuration Data To Layout • Finally we will add the items to the Layout. http://kb.vteamslabs.com

  15. http://kb.vteamslabs.com

  16. 6. Update Layout Files http://kb.vteamslabs.com

  17. USING Zend_Paginator to paginate records http://kb.vteamslabs.com

  18. 1. Update Model’s method to return Zend_Paginator object http://kb.vteamslabs.com

  19. 2. Update Controller’s method which lists records http://kb.vteamslabs.com

  20. 3. Update View File http://kb.vteamslabs.com

  21. 4. Creating Paginator Template • Create a new folder named partials in application/views/scripts. • Now create a file pagination-control.phtml. • Put in the following code in the file http://kb.vteamslabs.com

  22. 4.1 Adding Request Parameters to URL http://kb.vteamslabs.com

  23. 4.2 Adding Previous Page Control to Paginator http://kb.vteamslabs.com

  24. 4.3 Adding Total Pages List to Paginator http://kb.vteamslabs.com

  25. 4.4 Adding Next Page Control to Paginator http://kb.vteamslabs.com

  26. http://kb.vteamslabs.com

  27. http://kb.vteamslabs.com

  28. Managing table relationships using Zend_Db http://kb.vteamslabs.com

  29. 1. Defining Relationship Between Database Tables • In this case, we will take example of a simple CMS. • Have two tables page & node. • A page can have multiple nodes. • A Page can be parent to another page. http://kb.vteamslabs.com

  30. 2. Creating Models for Tables http://kb.vteamslabs.com

  31. 3. Defining Relationships for Models • Since pages table has a One-to-many Relationship with the content_nodestable, we need to do the following: • Model_Page: Tell Zend_Db_Table that the pages table is dependent on the content_nodes table. • Model_ContentNode: Tell Zend_Db_Table that the content_nodes table is related to the pages table, by doing the following: • Setting the related columns. • Adding reference table class (Model_Page). • Setting the referenced table columns. http://kb.vteamslabs.com

  32. 4. ContentNode to Page Relationship • Add the following code to the application/models/ContentNode.php: http://kb.vteamslabs.com

  33. 5. Page to Page Relationship • Add the following code to the application/models/Page.php: http://kb.vteamslabs.com

  34. 6. Fetching Dependent Rows http://kb.vteamslabs.com

  35. 7. Fetching Parent Rows http://kb.vteamslabs.com

  36. HANDLING SECURITY IN ZEND FRAMEWORK http://kb.vteamslabs.com

  37. Security in Zend Framework is done through: • Zend_Authsolely concerned with authenticating (and persisting) the application users. • Zend_Acl handles resources, roles (user roles), and which roles can access which resources. http://kb.vteamslabs.com

  38. 1. Managing Users • Normally we have two user types in a CMS: • Users: These are registered users who don’t have admin privileges. • Administrators: These are the site managers who can access any area of the CMS. Fields for Users Table: • `id` • `username` • `password` • `first_name` • `last_name` • `role` http://kb.vteamslabs.com

  39. 2. Creating User Model Class http://kb.vteamslabs.com

  40. User Authentication using Zend_Auth http://kb.vteamslabs.com

  41. LIST OF AVAILABLE ZEND_AUTH ADAPTERS • Some of the common Zend_Authadapters are: • Database table authentication. • Digest authentication. • LDAP authentication. • Open ID. Here, we will use Zend_Auth_Adapter_DbTable. http://kb.vteamslabs.com

  42. SAMPLE USAGE OF Zend_Auth http://kb.vteamslabs.com

  43. Creating the User Login http://kb.vteamslabs.com

  44. 1. Adding the Login Form to Controller http://kb.vteamslabs.com

  45. 2. Adding the Login Form to View http://kb.vteamslabs.com

  46. 3. Adding User Authentication First validate the form. If valid, then get the posted data: http://kb.vteamslabs.com

  47. 3. Adding User Authentication (continued …) • Creating Zend_Auth Adapter. • Pass the username & password. • Do the authentication. http://kb.vteamslabs.com

  48. 3. Adding User Authentication (continued …) • Get the Zend_Authauthentication data. • Store the valid Zend_Auth data in storage (PHP session). Then redirect the user to some page. • Show error message in case of invalid result. http://kb.vteamslabs.com

  49. http://kb.vteamslabs.com

  50. Logout for authenticated users http://kb.vteamslabs.com

More Related