When using yiic to create web applications, we have got SiteController and some views.
I’ve just looked at the about view for site views and very surprised because about.php says
/* @var $this SiteController */
My questions:
How $this is emplimented and is an instance of SiteController??
I think for each view, there should be an corresponding action inside controller. In this case for about view, there should be actionAbout inside SiteController. But I can’t find actionAbout there?
The url in Firefox’s address bar like this: localhost/mywebapp/index.php?r=site/page&view=about. Is there something to say about this url?
Hope someone give me an understandable explanation for these questions.
simply - if you import php file from within class method - $this will be still visible:
class XXX {
public function render() {
include 'view_file.php';
}
}
//viewfile.php will see $this as instance of XXX
as you can see in URL request ( r ) is made to "site/page" this means: SiteController::pageAction().
"about" is passed as a "view" parameter to that action and in picks proper view file according to the param.
One more thing to mention here is that there is no pageAction but instead there is ‘page’ action defined in actions() method of this controller which implements standard action that provides static pages based on GET param named ‘view’
the rendering of view take place inside of an action, so it seems like require("view.php") so the " $this" referrenced to the current controller inside view.php file
There is another automatically Yii method calls from Yii core
that take parameters (viewer’s folder) from method action() (see Keith Post)