This post covers my notes on Project CRUD (chapter 4) in Yii from the book "Web Application Development with Yii and PHP" by Jeffrey Winesett about learning Yii by taking a step-by-step approach to building a Web-based project task tracking system from conception through production deployment - software development life cycle (SDLC) issue-management application.
- Yii migration utility
- predefined validator classes and aliases
At the end of our efforts in this chapter, our application should allow users to create new projects, select from a list of existing projects, update/edit existing projects, and delete existing projects.
The Yii migration utility is a console command that we use with the yiic command-line tool. As a console command, it uses a configuration file specific to console commands, which, by default, is protected/config/console.php.
Creating a migration takes the general form of:
yiic migrate create <name>
The result:
Should be mentioned that Yii provides many predefined validator classes and provides aliases with which to reference these when defining rules (array validation rules for model attributes - public function rules()). The complete list of predefined validator class aliases as of Yii Version 1.1.12 is as follows:
- boolean: Alias of CBooleanValidator, validates the attribute that contains either true or false
- captcha: Alias of CCaptchaValidator, validates the attribute value that is same as the verification code displayed in a CAPTCHA
- compare: Alias of CCompareValidator, compares two attributes and validates they are equal
- email: Alias of CEmailValidator, validates the attribute value that is a valid e-mail address
- date: Alias of CDateValidator, validates the attribute value that is a valid date, time, or date-time value
- default: Alias of CDefaultValueValidator, assigns a default value to the attributes specified
- exist: Alias of CExistValidator, validates the attribute value against a specified table column in a database
- file: Alias of CFileValidator, validates the attribute value that contains the name of an uploaded file
- filter: Alias of CFilterValidator, transforms the attribute value with a specified filter
- in: Alias of CRangeValidator, validates if the data is within a prespecified range of values, or exists within a specified list of values
- length: Alias of CStringValidator, validates whether the length of the attribute value is within a specified range
- match: Alias of CRegularExpressionValidator, uses a regular expression to validate the attribute value
- numerical: Alias of CNumberValidator, validates whether the attribute value is a valid number
- required: Alias of CRequiredValidator, validates whether the attribute value is empty or not
- type: alias of CTypeValidator, validates whether the attribute value is of a specific data type
- unique: Alias of CUniqueValidator, validates that the attribute value is unique, and is compared against a database table column
- url: Alias of CUrlValidator, validates whether the attribute value is a valid URL
Download source code of chapter 4

Leave a Comment