34,79 €
The Yii framework is a rapidly growing PHP5 MVC framework often referred to as Rails for PHP. It has already become a solid base for many exciting web applications such as Stay.com and can be a good base for your developments, too. This book will help you to learn Yii quickly and in more depth for use in for your developments."Yii Application Development Cookbook" will show you how to use Yii efficiently. You will learn about taking shortcuts using core features, creating your own reusable code base, using test driven development, and many more topics that will give you a lot of experience in a moderate amount of time.The second edition fixes all errata found in the first edition and also features new recipes on the client side, HTTP caching, and using Composer with Yii.The chapters of the book are generally independent and since this book's goal is to enhance a practical approach to Yii development, you can start reading from the chapter you need most, be it Ajax and jQuery, Database, Active Record, and Model Tricks, or Extending Yii."Yii Application Development Cookbook" will help you to learn more about the Yii framework and application development practices in general, showing shortcuts and dangerous things you shouldn't do.With all the recipes grouped in 13 chapters, you will write your applications more efficiently using shortcuts and using Yii core functionality in a good way. The most interesting topics are; Yii application deployment, a guide to writing your own extensions, advanced error handling, debugging and logging, application security, performance tuning, and much more."Yii Application Development Cookbook" will help you to learn more about the Yii framework and application development practices in general. You will write your applications more efficiently using shortcuts and using Yii core functionality in a good way.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 351
Veröffentlichungsjahr: 2013
Copyright © 2013 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: August 2011
Second edition: April 2013
Production Reference: 1150413
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78216-310-7
www.packtpub.com
Cover Image by Alexander Makarov (<[email protected]>)
Author
Alexander Makarov
Reviewers
Maurizio Domba
Thomas Jantz
Acquisition Editor
Usha Iyer
Lead Technical Editor
Joel Noronha
Technical Editors
Hardik B. Soni
Ankita Meshram
Project Coordinator
Kranti Berde
Proofreaders
Maria Gould
Paul Hindle
Lawrence A. Herman
Indexer
Hemangini Bari
Graphics
Ronak Dhruv
Production Coordinator
Nilesh R. Mohite
Cover Work
Nilesh R. Mohite
Alexander Makarav is an experienced engineer from Russia and has been a Yii framework core team member since 2010. Before joining the Yii core team, he participated in the CodeIgniter community growth in Russia. In 2009, he finished the Russian translation of the framework documentation and created the Russian community website. In 2012, he released the Russian version of the book along with Russian community members. In the same year, he was the technical reviewer for three more books:
In his free time, Alexander writes technical blog at http://rmcreative.ru/, speaks at conferences, and enjoys movies, music, traveling, photography, and languages. He currently resides in Voronezh, Russia with his beloved wife and daughter.
Maurizio Domba is a frontend and backend web developer with over 20 years of professional experience in computer programming and 10 years in web development. He is part of the Yii core development team since August 2010 and is an active member of the Yii community.
At the moment he is developing intranet web applications for an export-import enterprise and working on other international projects, always trying to help others to improve their code and project usability.
When not programming the Web, he is programming his wife and kids, always with a smile on his face, open-hearted and open-minded. He loves climbing, martial arts, meditation, and salsa.
Thomas Jantz brings his background in language and art to his career as a web application development consultant at Plum Flower Software. His projects include an emphasis on rapid application development and user experience.
You might want to visit www.PacktPub.com for support files and downloads related to your book.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at <[email protected]> for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
http://PacktLib.PacktPub.com
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can access, read and search across Packt's entire library of books.
If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books. Simply use your login credentials for immediate access.
Yii is a very flexible and high-performance application development framework written in PHP. It helps building web applications, from small to large-scale enterprise applications. The framework name stands for Yes It Is (Yii). This is often the accurate and most concise response to inquiries from those new to Yii such as: Is it fast? Is it secure? Is it professional? Is it right for my next project? But the answer is an unequivocal, yes it is!
This cookbook contains 13 independent chapters full of recipes that will show you how to use Yii efficiently. You will learn about the hidden framework gems, using core features, creating your own reusable code base, using test-driven development, and many more topics that will bring your knowledge to a whole new level!
Chapter 1, Under the Hood, provides information about the most interesting Yii features hidden under the hood: events, import, autoloading, exceptions, component, widget configuration, and many more.
Chapter 2, Router, Controller, and Views, is about handy things concerning the Yii URL router, controllers, and views: URL rules, external actions and controllers, view clips, decorators, and more.
Chapter 3, AJAX and jQuery, focuses on the Yii's client side that is built with jQuery—the most widely used JavaScript library out there. It is very powerful and easy to learn and use. This chapter focuses on Yii-specific tricks rather than jQuery itself.
Chapter 4, Working with Forms, shows how Yii makes working with forms a breeze and documentation on it is almost complete. Still, there are some areas that need clarification and examples. Some of the topics covered in this chapter are creating validators and input widgets, uploading files, and using and customizing CAPTCHA.
Chapter 5, Testing Your Application, covers unit testing, functional testing, and generating code coverage reports. Recipes follow a test-driven development approach. You will write tests for several small applications and then implement functionality.
Chapter 6, Database, Active Record, and Model Tricks, is about working with databases efficiently, when to use models and when not to, how to work with multiple databases, how to automatically pre-process Active Record fields, and how to use powerful database criteria.
Chapter 7, Using Zii Components, covers data providers, grids, and lists: How to configure sorting and searching, how to use grids with multiple related models, how to create your own column types, and more.
Chapter 8, Extending Yii, shows not only how to implement your own Yii extension but also how to make your extension reusable and useful for the community. In addition, we will focus on many things you should do to make your extension as efficient as possible.
Chapter 9, Error Handling, Debugging, and Logging, reviews logging, analyzing the exception stack trace, and own error handler implementation.
Chapter 10, Security, provides information about keeping your application secure according to the general web application security principle "filter input, escape output." We will cover topics such as creating your own controller filters, preventing XSS, CSRF, and SQL injections, escaping output, and using role-based access control.
Chapter 11, Performance Tuning, shows how to configure Yii to gain extra performance. You will learn a few best practices for developing an application that will run smoothly until you have very high loads.
Chapter 12, Using External Code, focuses on using third-party code with Yii. We will use Zend Framework, Kohana, and PEAR but you will be able to use any code after learning how it works.
Chapter 13, Deployment, covers various tips that are especially useful on application deployment, when developing an application in a team, or when you just want to make your development environment more comfortable.
In order to run the examples in this book, the following software will be required:
Additionally, the following tools are not strictly required but are used for specific recipes:
If you are a developer with a good knowledge of PHP5, are familiar with the basics of Yii, have checked its definitive guide, and have tried to develop applications using Yii, then this book is for you. Knowledge of the object-oriented approach and MVC pattern will be a great advantage as Yii uses these extensively.
In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.
Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "To declare an event in your CComponent child class, you should add a method with a name starting with on."
A block of code is set as follows:
Any command-line input or output is written as follows:
New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "Now, go to the Gii controller generator and enter SecureController into the Base Class field."
Warnings or important notes appear in a box like this.
Tips and tricks appear like this.
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.
To send the author feedback about the book, simply fill in the form at http://yiicookbook.org/feedback.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
To get the example code files for this book visit http://yiicookbook.org/code.
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://yiicookbook.org/feedback, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on the book website at http://yiicookbook.org/errata.
Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at <[email protected]> with a link to the suspected pirated material.
We appreciate your help in protecting our authors, and our ability to bring you valuable content.
You can contact the book's author at http://yiicookbook.org/feedback. if you are having a problem with any aspect of the book, and he will do his best to address it.
In this chapter, we will cover:
In this chapter, we will cover the most interesting Yii features that are hidden "under the hood". These are mostly described in the framework API, but since they are not mentioned in the official guide (http://www.yiiframework.com/doc/guide/) or only mentioned very briefly, only experienced Yii developers usually use these. However, the features described here are relatively simple and using them makes development with Yii much more fun and productive.
