Symfony, Cakephp, and Zend.Pdf
Total Page:16
File Type:pdf, Size:1020Kb
Table of Contents Title Page Copyright Dedication Credits About the Authors Acknowledgments Introduction Who Should Read This Book? Comparative Approach Structure of This Book Source Code Conventions Contact Us Errata p2p.wrox.com 2 Chapter 1: Introducing Symfony, CakePHP, and Zend Framework What are Web Application Frameworks and How are They Used? Open Source PHP Web Frameworks Design Patterns in Web Frameworks Chapter 2: Getting Started Requirements Installation Configuration Hello World! Structure IDE Support Chapter 3: Working with Databases Object-Relational Mapping Database Configuration Communication with a Database Chapter 4: Your First Application in the Three Frameworks 3 Design Symfony CakePHP Zend Framework Chapter 5: Forms Field Validation Customizing Forms Using Captcha as Spam Protection Chapter 6: Mailing Creating Mailing Applications SwiftMailer CakePHP's Mailing Component Zend Mailer PHPMailer Chapter 7: Searching Problem Solutions 4 Chapter 8: Security Setting Secure Connections Securing a Profile Form Against XSS and Injection Attacks CSRF Chapter 9: Templates Creating a Simple Image Gallery by Using Helpers and Lightbox Using Template Engines within Web Frameworks Overview of Other Add-on Template Engines Chapter 10: AJAX Introducing AJAX Autocomplete Dynamic Popup Windows AJAX User Chat Chapter 11: Making Plug-ins Symfony CakePHP 5 Zend Framework Chapter 12: Web Services Restful News Reading Providing Soap Web Services in E-Commerce Applications Chapter 13: Back End Symfony CakePHP Zend Framework Feature Summary Chapter 14: Internationalization Internationalization Defined Symfony CakePHP Zend Framework Chapter 15: Testing Introducing Testing 6 Black-Box Registration Form Testing Using Functional Tests CMS Tests Automation Using Selenium Mailing Unit Testing Chapter 16: User Management Basic User Management Identifying Users Using LDAP Implementation Chapter 17: Performance Using JMeter for Stress, Load, and Performance Tests Benchmarking Development Speed Chapter 18: Summary Features And the Winner Is… Appendix A: Web Resources General Symfony CakePHP 7 Zend Framework Design Patterns ORM Databases LDAP Searching Testing Security PDF Web Services Mailing Templates IDE Javascript AJAX CMS CodeIgniter 8 Lithium Agavi Appendix B: CodeIgniter, Lithium, and Agavi with Code Examples CodeIgniter Lithium Agavi Glossary of Acronyms and Technical Terms Index 9 10 Building PHP Applications with Symfony™, CakePHP, and Zend® Framework Published by Wiley Publishing, Inc. 10475 Crosspoint Boulevard Indianapolis, IN 46256 www.wiley.com Copyright ©2011 by , Karol Przystalski, and Leszek Nowak Published by Wiley Publishing, Inc., Indianapolis, Indiana Published simultaneously in Canada ISBN: 978-0-470-88734-9 ISBN: 978-1-118-06792-5 (ebk) ISBN: 978-1-118-06791-8 (ebk) ISBN: 978-1-118-06790-1 (ebk) No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, 11 without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions. Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including without limitation warranties of fitness for a particular purpose. No warranty may be created or extended by sales or promotional materials. The advice and strategies contained herein may not be suitable for every situation. This work is sold with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional services. If professional assistance is required, the services of a competent professional person should be sought. Neither the publisher nor the author shall be liable for damages arising herefrom. The fact that an organization or Web site is referred to in this work as a citation and/or a potential source of further information does not mean that the author or the publisher endorses the information the organization or Web site may provide or recommendations it may make. Further, readers should be aware that Internet Web sites listed in this work may have changed or disappeared between when this work was written and when it is read. 12 For general information on our other products and services please contact our Customer Care Department within the United States at (877) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002. Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books. Library of Congress Control Number: 2010942182 Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Wrox Programmer to Programmer, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and other countries, and may not be used without written permission. Symfony is a trademark of Fabien Potencier. Zend is a registered trademark of Zend Technologies, Ltd. All other trademarks are the property of their respective owners. Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book. 13 For my beloved Olcia, who keeps inspiring me to achieve goals I could have never dreamed of. The way you are able to solve with your pure wisdom all the analyti-cally unsolvable problems, your dedication, and your sense of humor still amaze me every day. And the sweet cakes (no PHP added) you baked for me while I was writ-ing this book were simply delicious. I would also like to thank my parents for their continuing faith and support. — For Agata. —Karol Przystalski I dedicate this book to my parents, for their constant love and support. They made this book possible. I also warn any readers of this book not to try and run the code examples backward! It may cause hellspawns to appear out of thin air. —Leszek Nowak 14 Credits Executive Editor Carol Long Project Editor Tom Dinse Technical Editor Wim Mostrey Production Editor Daniel Scribner Copy Editor Nancy Sixsmith Editorial Director Robyn B. Siesky Editorial Manager Mary Beth Wakefield Freelancer Editorial Manager Rosemarie Graham 15 Associate Director of Marketing Ashley Zurcher Production Manager Tim Tate Vice President and Executive Group Publisher Richard Swadley Vice President and Executive Publisher Barry Pruett Associate Publisher Jim Minatel Project Coordinator, Cover Katherine Crocker Proofreader Word One Indexer Robert Swanson Cover Designer 16 Michael E. Trent Cover Image © Xiaoke Ma/istockphoto.com 17 About the Authors is a video games, web applications, and C++ software developer. He works as Brain-Computer Interface researcher and lecturer at Jagiellonian University in Kraków. KAROL PRZYSTALSKI is a Software Quality Engineer at Sabre Holdings and a PhD student at Jagiellonian University in Kraków. He has worked with Symfony since its earliest versions and wrote a book on the Symfony framework. LESZEK NOWAK has years of experience in web development and graphics design with such frameworks as Django, CakePHP and CodeIgniter. He also works with 3D modelling, animation, image recognition, and artificial intelligence development. He says, “Science is fun, if used in games.” 18 Acknowledgments NO BOOK IS THE SOLE effort of its authors, especially such a long book. It took long months and countless cups of coffee to keep us awake and writing and programming the code examples. We could not have made it through this if not for the help and patience of many kind souls. First of all, we want to say a big THANK YOU! to the Wiley/Wrox team we had the pleasure of working with. Carol Long showed great patience and motivated us when we were down. Tom Dinse and Nancy Sixsmith worked hard to get our English right. Wim Mostrey made sure that all technical matters are 100% correct. Ashley Zurcher helped to successfully deliver the book to the market, and Helen Russo took care of our legal matters. It was really fun to work with you folks! We also want to thank our superiors on the faculty of Physics, Astronomy, and Applied Computer Science of Jagiellonian University in Kraków: dr hab. Ewa Grabska, prof. dr hab. Maciej Ogorzałek, prof. dr hab. Maciej A. Nowak, and dr hab. Paweł W grzyn, who were really supportive and did their best not to swamp us with additional jobs while we were busy writing. Finally, our thanks go also to all the developers who dedicated their precious time to write good documentation and share their knowledge. 19 Introduction Honest differences are often a healthy sign of progress. —Mahatma Gandhi For a long time, PHP was disregarded as a language not serious enough for rich web applications. Everyone knew it was popular and perhaps good for small one-shot projects, but all the praise was reserved for the aristocratic elite of frameworks such as Spring, Ruby on Rails, or Django. Only recently has the situation changed, and it changed dramatically. In 2007, it became clear that PHP has not just one, but three major web application frameworks extending capabilities of this language: Symfony, CakePHP, and Zend Framework. The pace of development was fast and steady. Object-oriented source code written in PHP5 was elegant and maintainable. More and more new projects began using them, and their successful completion made the PHP frameworks even more popular. Nowadays, the popularity of PHP web development frameworks surpasses all others (the evidence is inside this book), and they have become a leading force in the industry.