You are previewing Yii 1.1 Application Development Cookbook.
O'Reilly logo
Yii 1.1 Application Development Cookbook

Book Description

Over 80 recipes to help you master using the Yii PHP framework

  • Learn to use Yii more efficiently through plentiful Yii recipes on diverse topics

  • Make the most efficient use of your controller and views and reuse them

  • Automate error tracking and understand the Yii log and stack trace

  • Full of practically useful solutions and concepts that you can use in your application, with clearly explained code and all the necessary screenshots

  • In Detail

    When Alex told me he was about to write a Yii cookbook about a year ago, I was wondering how original it would be, considering the fact that there was already an online user-contributed cookbook (aka. Yii wiki). It turned out Alex produced a book that is not only full of wisdom about how to use Yii effectively, but also presented in such a systematic way that it can be taken as an essential companion book to the definitive guide to Yii. In fact, Alex has successfully intrigued the interest of every member in the Yii developer team when he asked for review and comments on his newly finished book chapters.

    As the founder and the lead developer of the Yii framework, I feel this book is a must-read for every Yii programmer. While this book does not describe directly the rules set by Yii, it shows how to program with Yii from a practical perspective. People who are driven by tight project schedules will find this book very handy as it gives ready-to-use solutions to many problems they may face in their projects; people who are already familiar with Yii will also find this book very informative as most problem solutions given in the book can be considered as officially recommended because they have undergone thorough review of every Yii developer team member. Alex, through this book and his active participation in the Yii project, proved himself to be a great programmer as well as a good writer.

    Yii framework is a rapidly growing PHP5 MVC framework often referred to as Rails for PHP. It has become a solid base for many exciting web applications such as Stay.com and Russia Today's meetfriends.rt.com and can be a good base for your developments. Yii is an object-oriented, high-performance, component-based PHP web application framework. Yii is pronounced as Yee and is an acronym for "Yes It Is!".

    Familiar with Yii and want to exploit it to its full potential, but do not know how to go about it? Yii 1.1 Application Development Cookbook will show you how to use Yii efficiently. You will learn about implementing shortcuts using core features, creating your own reusable code base, using test-driven development, and many more topics that will escalate your knowledge in no time at all!

    Yii 1.1 Application Development Cookbook will help you learn more about Yii framework and application development practices in general with demonstrations of shortcuts and information about dangerous things you should not do.

    Grouped in 13 chapters, the recipes will assist you to write your applications exploiting Yii core functionality to its full potential. The chapters are generally independent of each other and you can start reading from the chapter you need most, whether it is "AJAX and jQuery", "Database, Active Record and Model Tricks" or "Extending Yii". The most interesting topics include Yii application deployment, a guide to writing your own extensions, advanced error handling, debugging and logging, application security, and performance tuning.

    Yii 1.1 Application Development Cookbook will help you utilize Yii functionalities completely and efficiently.

    A practical cookbook on the Yii MVC framework covering the most important internal features of Yii and useful tips on Yii application development

    Table of Contents

    1. Yii 1.1 Application Development Cookbook
      1. Yii 1.1 Application Development Cookbook
      2. Credits
      3. Foreword
      4. About the Author
      5. About the Reviewers
      6. www.PacktPub.com
        1. Support files, eBooks, discount offers, and more
          1. Why Subscribe?
          2. Free Access for Packt account holders
      7. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      8. 1. Under the Hood
        1. Introduction
        2. Using getters and setters
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        3. Using Yii events
          1. How to do it...
          2. There's more...
            1. Further reading
          3. See also
        4. Using import and autoloading
          1. How to do it...
          2. How it works...
          3. There's more...
        5. Using exceptions
          1. How to do it…
          2. How it works…
          3. There's more...
        6. Configuring components
          1. How to do it…
          2. How it works…
          3. There's more...
          4. See also
        7. Configuring widget defaults
          1. How to do it…
          2. See also
        8. Using Yii core collections
          1. How to do it…
        9. Working with request
          1. How to do it…
          2. There's more...
      9. 2. Router, Controller, and Views
        1. Introduction
        2. Configuring URL rules
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Further reading
          5. See also
        3. Generating URLs by path
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        4. Using regular expressions in URL rules
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        5. Creating URL rules for static pages
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        6. Providing your own URL rules at runtime
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        7. Using base controller
          1. Getting ready
          2. How to do it...
          3. How it works...
        8. Using external actions
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more…
        9. Displaying static pages with CViewAction
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Further reading
          5. See also
        10. Using flash messages
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more…
        11. Using controller context in a view
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more…
        12. Reusing views with partials
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more…
          5. See also
        13. Using clips
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        14. Using decorators
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more…
          5. See also
        15. Defining multiple layouts
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        16. Paginating and sorting data
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more…
      10. 3. AJAX and jQuery
        1. Introduction
        2. Loading a block through AJAX
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Prevent including a bundled jQuery
            2. Further reading
          5. See also
        3. Managing assets
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. What is inside the assets directory?
            2. Publishing an entire directory
            3. Further reading
          5. See also
        4. Including resources into the page
          1. How to do it...
          2. How it works...
          3. There's more
            1. Using custom script packages
            2. Registering linked resources
            3. Registering meta tags
            4. Further reading
          4. See also
        5. Working with JSON
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more
          5. See also
        6. Passing configuration from PHP to JavaScript
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        7. Handling variable number of inputs
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more…
          5. See also
      11. 4. Working with Forms
        1. Introduction
        2. Writing your own validators
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Further reading
        3. Uploading files
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. File validation
            2. Further reading
          5. See also
        4. Adding CAPTCHA
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Further reading:
          5. See also
        5. Customizing CAPTCHA
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        6. Creating a custom input widget with CInputWidget
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
      12. 5. Testing your Application
        1. Introduction
        2. Setting up the testing environment
          1. Getting ready
          2. How to do it...
          3. There's more...
          4. See also
        3. Writing and running unit tests
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        4. Using fixtures
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        5. Testing the application with functional tests
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        6. Generating code coverage reports
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
      13. 6. Database, Active Record, and Model Tricks
        1. Introduction
        2. Getting data from a database
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        3. Defining and using multiple DB connections
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Cross-database relations
            2. Further reading
          5. See also
        4. Using scopes to get models for different languages
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        5. Processing model fields with AR event-like methods
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Further reading
          5. See also
        6. Applying markdown and HTML
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Makdown syntax
            2. Yii markdown wraper and usage
          5. See also
        7. Highlighting code with Yii
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Yii code highlighter
            2. More code highlighters
          5. See also
        8. Automating timestamps
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        9. Setting an author automatically
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        10. Implementing single table inheritance
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        11. Using CDbCriteria
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
      14. 7. Using Zii Components
        1. Introduction
        2. Using data providers
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Further reading
          5. See also
        3. Using grids
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Using data from related Active Record models
            2. Further reading
          5. See also
        4. Using lists
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Adding sorting
            2. Customizing templates
            3. Customizing markup and data displayed
            4. Further reading
          5. See also
        5. Creating custom grid columns
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
      15. 8. Extending Yii
        1. Introduction
        2. Creating model behaviors
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. CActiveRecordBehavior and CModelBehavior
            2. More behavior types
            3. Further reading
          5. See also
        3. Creating components
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Overriding existing application components
            2. Further reading
          5. See also
        4. Creating reusable controller actions
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Further reading
          5. See also
        5. Creating reusable controllers
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        6. Creating a widget
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        7. Creating CLI commands
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Custom help
            2. Further reading
          5. See also
        8. Creating filters
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        9. Creating modules
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        10. Creating a custom view renderer
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Further reading
          5. See also
        11. Making extensions distribution-ready
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
      16. 9. Error handling, Debugging, and Logging
        1. Introduction
        2. Using different log routes
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Yii::trace vs Yii::log
            2. Yii::beginProfile and Yii::endProfile
            3. Log messages immediately
            4. Further reading
          5. See also
        3. Analyzing the Yii error stack trace
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        4. Logging and using the context information
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        5. Implementing your own smart 404 handler
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Further reading
          5. See also
      17. 10. Security
        1. Introduction
        2. Using controller filters
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        3. Using CHtml and CHtmlPurifier to prevent XSS
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. XSS types
            2. Configuring the HTML purifier
            3. HTML purifier performance
            4. Further reading
          5. See also
        4. Preventing SQL injections
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        5. Preventing CSRF
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Extra measures
            2. Using GET and POST properly
            3. Further reading
          5. See also
        6. Using RBAC
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Naming RBAC nodes
            2. A way to keep the hierarchy simple and efficient
            3. Avoiding RBAC
            4. Further reading
          5. See also
      18. 11. Performance Tuning
        1. Introduction
        2. Following best practices
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Server-side performance is just a part of the big picture
            2. Things to be done without using Yii
            3. Active record versus query builder and SQL
            4. Always check for slow queries first
            5. Cache or save results of "heavy" processes
            6. Handling too much processing
            7. Further reading
          5. See also
        3. Speeding up sessions handling
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        4. Using cache dependencies and chains
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        5. Profiling an application with Yii
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
      19. 12. Using External Code
        1. Introduction
        2. Using Zend Framework from Yii
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        3. Customizing the Yii autoloader
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Further reading
          5. See also
        4. Using Kohana inside Yii
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Further reading
          5. See also
        5. Using PEAR inside Yii
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
      20. 13. Deployment
        1. Introduction
        2. Changing the Yii directories layout
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        3. Moving an application out of webroot
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        4. Sharing the framework directory
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        5. Moving configuration parts into separate files
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        6. Using multiple configurations to simplify the deployment
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        7. Implementing and executing cron jobs
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Further reading
          5. See also
        8. Maintenance mode
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also