What Is The Coresponding Action For About View

Hello everyone!

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:

  1. How $this is emplimented and is an instance of SiteController??

  2. 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.

Thank you for reading my post!

Best regard!

Hung

  1. 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



  1. 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’

For your first question, $this in the view corresponds to the controller that rendered it, in this case SiteController.

For the other question, the about page is a static page. See here.

Hi Trinh Duy Hung

  1. 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

  2. There is another automatically Yii method calls from Yii core

that take parameters (viewer’s folder) from method action() (see Keith Post)

For example

public function actions()

{

return array(


    'page'=>array(


        'class'=>'CViewAction',


    ),


);

}

for example www.yourdomain.com?r=site/pages&view=yourview

In this alternative way the core Yii system renders the pages/yourview.php view file

Ok. Now I understand the issue.

Thank you guys!