Yii documentation
Qiang Xue and Xiang Wei Zhuo
Copyright 2008-2009. All Rights Reserved.
Contents
Contents
i
License
xi
1 Getting Started 1.1 1.2 The Definitive Guide to Yii . . . . . . . . . . . . . . . . . . . . . . . . . . . New Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3Version 1.1.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Version 1.0.11 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Version 1.0.10 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Version 1.0.8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Version 1.0.7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Version 1.0.6 . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . Version 1.0.5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1 1 1 1 2 2 2 2 2 3 3 3 4 4 4 5 5
Upgrading from Version 1.0 to 1.1 . . . . . . . . . . . . . . . . . . . . . . . 1.3.1 1.3.2 1.3.3 1.3.4 Changes Related with Model Scenarios . . . . . . . . . . . . . . . . . Changes Related with Eager Loading for Relational ActiveRecord . Changes Related with Table Alias in Relational Active Record . . . Changes Related with Tabular Input . . . . . . . . . . . . . . . . . .
1.4
What is Yii . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.4.1 Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ii 1.4.2 1.4.3 1.5
Contents What is Yii Best for? . . . . . . . . . . .. . . . . . . . . . . . . . . How is Yii Compared with Other Frameworks? . . . . . . . . . . . . 5 5 5 6 6
Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.5.1 Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.6
Creating First Yii Application . . . . . . . . . . . . . . . . . . . . . . . . . . 1.6.1 1.6.2
Connecting toDatabase . . . . . . . . . . . . . . . . . . . . . . . . . 11 Implementing CRUD Operations . . . . . . . . . . . . . . . . . . . . 11
2 Fundamentals 2.1
15
Model-View-Controller (MVC) . . . . . . . . . . . . . . . . . . . . . . . . . 15 2.1.1 A Typical Workflow . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2.2
Entry Script . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . 17 2.2.1 Debug Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.3
Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 Application Configuration . . . . . . . . . . . . . . . . . . . . . . . . 18 Application Base Directory . . . . . . . . . . . . . . . . . . . . . . . 19 ApplicationComponent . . . . . . . . . . . . . . . . . . . . . . . . . 19 Core Application Components . . . . . . . . . . . . . . . . . . . . . 20 Application Lifecycles . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2.4
Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 2.4.1 2.4.2 2.4.3 2.4.4 Route . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . 22 Controller Instantiation . . . . . . . . . . . . . . . . . . . . . . . . . 23 Action . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
2.5
Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Contents 2.6
iii
View . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 2.6.1 2.6.2 2.6.3 Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 Widget . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 System View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
2.7
Component . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ....
Regístrate para leer el documento completo.