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, 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. 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. 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. For Agata. 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 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 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 Michael E. Trent Cover Image Xiaoke Ma/istockphoto.com 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 Krakw.
KAROL PRZYSTALSKI is a Software Quality Engineer at Sabre Holdings and a PhD student at Jagiellonian University in Krakw. 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.
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 Krakw: dr hab. Ewa Grabska, prof. dr hab. dr hab. Maciej A. Maciej A.
Nowak, and dr hab. Pawe Wgrzyn, 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. 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.