Yii Framework Forum: What Is The Coresponding Action For About View - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

What Is The Coresponding Action For About View Rate Topic: -----

#1 User is offline   Trinh Duy Hung 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 73
  • Joined: 26-October 12

Posted 23 November 2012 - 09:19 AM

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
0

#2 User is offline   redguy 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 780
  • Joined: 02-July 10
  • Location:Central Poland

Posted 23 November 2012 - 09:33 AM

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

2. 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'
red
0

#3 User is offline   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,520
  • Joined: 04-March 10
  • Location:UK

Posted 23 November 2012 - 09:34 AM

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

#4 User is offline   KonApaz 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,311
  • Joined: 21-February 11
  • Location:Greece

Posted 23 November 2012 - 09:39 AM

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
Yii is the best php framework in the world!
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
0

#5 User is offline   Trinh Duy Hung 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 73
  • Joined: 26-October 12

Posted 23 November 2012 - 11:55 PM

Ok. Now I understand the issue.

Thank you guys!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users