You are viewing revision #5 of this wiki article.
This version may not be up to date with the latest version.
You may want to view the differences to the latest version or see the changes made in this revision.
Reading the Yii doc ¶
What to read: ¶
Almost all information you need while working with yii are written in Class Reference.
The point is just to know how to find out them.
For find this information, you have to understand what is Yii::app() and what is "this" in the context in wich you are.
Yii::app(): your best friend during programming ¶
In each point of your application code (view, controller, widget, model, module) you can call Yii:app().
This will give you the actual instance of CApplication that is running.
If you are developing a Web application, you will get an instance of CWebApplication, if you are developing a Console app, you will get an instance of CConsoleApplication.
This object is the one that is configured through config/main.php, is the backbone of Yii. So in main.php you can configure each property you see, or add new compomentes that can be invoked via Yii::app()->myComponent.
What can I do with this Yii::app()? ¶
You can do whatever is written here: CApplication.
Taking a look at this page, you will notice lot if interesting stuff, like db, urlManager, numberFormatter and many other.
So, if you need to format a number, you can use the actual number formatter, calling Yii::app()->numberFormatter->
And then what? Simply click on the link named numberFormatter on the doc page, and you will be redirected to the CNumberFormatter page, where you can see all possible properties, methods and event available.
$this: the second good friend in Yii ¶
Another important element is the variable $this. It is the actual object we are implementing. So in a controller, it will be the actual controller, you can check all possible methods on this page.
Remember that when you are in a view of a controller (so not in protected/components/views but in protected/views/controllerID), $this is an instance if CController too, the one that called render or renderPartial.
If you are in a model, $this is the instance of CModel (CFormModel or CActiveRecord).
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.