
Zend Framework 1.8 Web Application Development Design, develop, and deploy feature-rich PHP web applications with this MVC framework Keith Pope BIRMINGHAM - MUMBAI This material is copyright and is licensed for the sole use by Vadim Kudria on 4th October 2009 6352 108th St, , Forest Hills, , 11375 Zend Framework 1.8 Web Application Development Copyright © 2009 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: September 2009 Production Reference: 1160909 Published by Packt Publishing Ltd. 32 Lincoln Road Olton Birmingham, B27 6PA, UK. ISBN 978-1-847194-22-0 www.packtpub.com Cover Image by Vinayak Chittar ([email protected]) This material is copyright and is licensed for the sole use by Vadim Kudria on 4th October 2009 6352 108th St, , Forest Hills, , 11375 Credits Author Editorial Team Leader Keith Pope Akshara Aware Reviewers Project Team Leader Wenbert Del Rosario Lata Basantani Md. Mahmud Ahsan Project Coordinator Acquisition Editor Rajashree Hamine Rashmi Phadnis Proofreader Development Editor Lynda Sliwosk Ved Prakash Jha Jeff Orloff Technical Editor Graphics Pallavi Kachare Nilesh Mohite Copy Editor Production Coordinator Leonard D'Silva Shantanu Zagade Indexer Cover Work Hemangini Bari Shantanu Zagade This material is copyright and is licensed for the sole use by Vadim Kudria on 4th October 2009 6352 108th St, , Forest Hills, , 11375 About the Author Keith Pope has over ten years of experience in web-related industries and has had a keen interest in programming from an early age. Keith currently works in the airline industry as a technical project manager, providing entertainment systems for aircraft. He has been working with the Zend Framework since its first preview release, using it in many of his work and personal projects. I would like to thank my wife; without her support and patience, this book would not have been possible. I would also like to thank Matthew Weier O'Phinney who has been instrumental in the success of the Zend Framework project as well as giving lots of time to the mailing lists, answering both mine and others questions. The rest of the Zend team for all their hard work while creating a great framework that I could write about. Rob Allen and Alex Mace for general help and support. The technical reviewers and the team at Packt for their hard work in getting everything together. Derek Au for his bug reports. Big thanks to my family, the Adkins family, Phil Dunsford, Martin Williams, Tom Hoddell, Sally Hoddell, the Allpay team, Francesca Oliveri, Lucy Hughes-Martin, and Rob Whittle; you all supported me in various ways. This material is copyright and is licensed for the sole use by Vadim Kudria on 4th October 2009 6352 108th St, , Forest Hills, , 11375 About the Reviewers Wenbert Del Rosario is from Cebu, Philippines. He started his career as a web developer in college, learning PHP and Adobe Photoshop. He works with open source technologies—Zend Framework, Code Igniter, MySQL, and jQuery are some of the tools he has under his sleeve. He likes to keep it simple and believes that being mindful of best practices in software development can be more effective than adopting every latest technology. In his free time, he loves to work on personal projects using PHP, Javascript, and MySQL. He also does some freelance jobs and consulting from time to time. All in all, he is very passionate about what he does and is a big fan of open source software. Wenbert has worked for Lexmark Research and Development Corporation in Cebu. He develops in-house web-based applications using Apache, PHP, MySQL, and Linux. Some of his web applications are used in different geographc regions (USA, Europe, and Asia Pacific) by Lexmark employees, while other small but significant ones are used locally by Lexmark Cebu employees. I would like to thank my family. My mother, Wenia, who is always very supportive and understanding. My brothers, Andrew, John, and Alberto. And my sister Jonina Mae. To my father, Luis, who passed away a few years ago and to God. This material is copyright and is licensed for the sole use by Vadim Kudria on 4th October 2009 6352 108th St, , Forest Hills, , 11375 Md. Mahmud Ahsan is a freelance consultant currently working as a software engineer in Berkeley-based i2we, inc. Mahmud received a Bachelor's degree in Computer Science and Engineering from the International Islamic University Chittagong, in Bangladesh. He is also a Zend Certified Engineer. He has about four years of experience in the world of PHP. He has extensively worked on small and large scale social networking web applications developed in PHP and Zend Framework. I'm grateful to my parents and Hasin Hayder (author at Packt Publishing). I would also like to thank my wife Jinat Jahan for her consistent support. This material is copyright and is licensed for the sole use by Vadim Kudria on 4th October 2009 6352 108th St, , Forest Hills, , 11375 Table of Contents Preface 1 Chapter 1: Creating a Basic MVC Application 9 Overview of MVC architecture 10 Setting up the environment 10 Installation 11 Creating the project structure 11 Application directory structure 13 Bootstrapping 14 The index file 14 Application configuration 16 The bootstrap file 17 Your first controller 18 The Action Controller 19 Subclassing 19 Initialization 20 Actions 21 The standard router 24 Utility methods 27 Action Helpers 29 Your first view 30 View directories 31 Creating a view 31 View Helpers 35 URL View Helper 35 View customization 37 Handling errors 38 Summary 40 This material is copyright and is licensed for the sole use by Vadim Kudria on 4th October 2009 6352 108th St, , Forest Hills, , 11375 Table of Contents Chapter 2: The Zend Framework MVC Architecture 41 Zend framework MVC overview 41 What is a request 42 Request handling 42 Abstractness of MVC components 45 The Front Controller 45 Design 45 Defaults 46 Using the Front Controller 47 Invocation parameters 47 Options 48 Modules, controllers, and actions 48 MVC component customization 51 Plugins 52 The router 53 Design 54 Defaults 54 Using the router 55 Zend_Controller_Router_Route 56 Zend_Controller_Router_Route_Static 59 Zend_Controller_Router_Route_Regex 59 Zend_Controller_Router_Route_Hostname 63 Zend_Controller_Router_Route_Chain 64 Zend_Config 65 The Dispatcher 67 Design 67 Request dispatching 67 Using the Dispatcher 69 The Request object 70 Design 71 Defaults 71 Using the Request object 71 The HTTP Request object 73 The Response object 75 Design 75 Defaults 76 Using the Response object 76 Summary 80 Chapter 3: Storefront Basic Setup 81 Getting started 81 Software requirements 82 Coding standards 82 The Storefront requirements 82 [ ii ] This material is copyright and is licensed for the sole use by Vadim Kudria on 4th October 2009 6352 108th St, , Forest Hills, , 11375 Table of Contents The Storefront overview 83 Basic structure and setup 83 The directory structure 84 Bootstrapping with Zend_Application 85 Zend_Application basics 85 Bootstrapping the storefront 86 Zend_Application configuration 88 The bootstrap class 94 Creating the bootstrap resources 96 Bootstrapping complete 100 The basic layout 100 A little task for you 102 Building the Storefront 102 The Storefront database 104 Database installation 104 Product table 105 ProductImage table 106 Category table 106 The user table 107 Introducing Zend_Db 107 Adding Zend_Db to the Storefront 108 Logging and debugging 108 Zend_Debug 109 Zend_Log 109 Adding Zend_Log to the Storefront 109 Using the logger 111 Database profiling with Zend_Log 113 Summary 114 Chapter 4: Storefront Models 115 Models in the Zend Framework 115 Model design 116 The application stack 116 Fat Model Skinny Controller 117 Fat Controller 117 Fat Model 118 Model design strategies 120 Direct inheritance 120 Has-a relationship (composition) 122 Domain Model 123 Further reading 124 Storefront Models 125 Model Resources 125 Managing Model Resources 126 Model Resource data sources 126 [ iii ] This material is copyright and is licensed for the sole use by Vadim Kudria on 4th October 2009 6352 108th St, , Forest Hills, , 11375 Table of Contents Model Resource Items 127 Resource Item business logic 127 Loading Models and Resources 129 Zend_Loader_Autoloader_Resource 129 Resource Autoloading 129 The SF Library 131 Summary 132 Chapter 5: Implementing the Catalog 133 Getting started 133 Creating the Catalog Model and Resources 134 Catalog model skeleton 134 Naming conventions 135 Catalog methods 136 Catalog Model Resources 137 Zend_Db_Table 138 Model Resource Items 140 Implementing the Catalog Model 143 Model Resource interfaces 143 Model Resource implementation 146 Catalog Model 156 Loading Models and other assets
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages376 Page
-
File Size-