PacktLib: Yii Application Development Cookbook - Second Edition

Yii Application Development Cookbook Second Edition


About the Author

About the Reviewers


Under the Hood


Using getters and setters

Using Yii events

Using import and autoloading

Using exceptions

Configuring components

Configuring widget defaults

Using Yii core collections

Working with requests

Router, Controller, and Views


Configuring URL rules

Generating URLs by path

Using regular expressions in URL rules

Creating URL rules for static pages

Providing your own URL rules at runtime

Using a base controller

Using external actions

Displaying static pages with CViewAction

Using flash messages

Using the controller context in a view

Reusing views with partials

Using clips

Using decorators

Defining multiple layouts

Paginating and sorting data

AJAX and jQuery


Loading a block through AJAX

Managing assets

Including resources in the page

Working with JSON

Passing configuration from PHP to JavaScript

Handling variable number of inputs

Rendering content at the client side

Working with Forms


Writing your own validators

Uploading files


Customizing CAPTCHA

Creating a custom input widget with CInputWidget

Testing Your Application


Setting up the testing environment

Writing and running unit tests

Using fixtures

Testing the application with functional tests

Generating code coverage reports

Database, Active Record, and Model Tricks


Getting data from a database

Defining and using multiple DB connections

Using scopes to get models for different languages

Processing model fields with AR event-like methods

Applying markdown and HTML

Highlighting code with Yii

Automating timestamps

Setting up an author automatically

Implementing single table inheritance

Using CDbCriteria

Using Zii Components


Using data providers

Using grids

Using lists

Creating custom grid columns

Extending Yii


Creating model behaviors

Creating components

Creating reusable controller actions

Creating reusable controllers

Creating a widget

Creating CLI commands

Creating filters

Creating modules

Creating a custom view renderer

Making extensions distribution-ready

Error Handling, Debugging, and Logging


Using different log routes

Analyzing the Yii error stack trace

Logging and using the context information

Implementing your own smart 404 handler



Using controller filters

Using CHtml and CHtmlPurifier to prevent XSS

Preventing SQL injections

Preventing CSRF

Using RBAC

Performance Tuning


Following best practices

Speeding up session handling

Using cache dependencies and chains

Profiling an application with Yii

Leveraging HTTP caching

Using External Code


Using Zend Framework from Yii

Customizing the Yii autoloader

Using Kohana inside Yii

Using PEAR inside Yii

Using Composer with Yii



Changing the Yii directory layout

Moving an application out of webroot

Sharing the framework directory

Moving configuration parts into separate files

Using multiple configurations to simplify the deployment

Implementing and executing cron jobs

Maintenance mode