Yii Framework Forum: get current webpage in yii? how? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

get current webpage in yii? how? the page name, not its page count Rate Topic: ****- 1 Votes

#1 User is offline   YuriKolovsky 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 45
  • Joined: 18-August 09
  • Location:Malaga, Spain

Posted 08 September 2009 - 06:50 AM

once again a simple question to the forum...

is there a build in method in yii to return the current page?
i don't mean the page number, i mean the actual page.

so for example if a page is in site/index.php
then i want yii to tell me that the page is "site/index.php" or "site/index"
0

#2 User is offline   Dave 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 187
  • Joined: 09-October 08

Posted 08 September 2009 - 07:09 AM

Yii::app()->getController() returns the current controller. With CController::getAction() you can access the current action.
0

#3 User is offline   pestaa 

  • past Yii dev member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 705
  • Joined: 07-May 09
  • Location:Hungary

Posted 08 September 2009 - 07:15 AM

For the url, access Yii::app()->request->requestUri. For the other case, see the post above.
1

#4 User is offline   YuriKolovsky 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 45
  • Joined: 18-August 09
  • Location:Malaga, Spain

Posted 08 September 2009 - 07:47 AM

Dave gave exactly what i wanted, thanks!


i am currently getting it like this

$curpage = Yii::app()->getController()->getAction()->controller->id;
$curpage .= '/'.Yii::app()->getController()->getAction()->controller->action->id;
return $curpage;


not sure if this is how its meant to be taken out...



as for the Yii::app()->request->requestUri.
isn't $_SERVER['REQUEST_URI'] the same thing?
1

#5 User is offline   phpdevmd 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 73
  • Joined: 16-April 09

Posted 08 September 2009 - 10:27 AM

Outside of the view file I use
Yii::app()->controller->getId()
Yii::app()->controller->getAction()->getId()


url then would be something like
CHtml::normalizeUrl(array(Yii::app()->controller->getId().'/'.Yii::app()->controller->getAction()->getId()))



inside view simplify with
$this->getId()
$this->getAction()->getId()



See http://www.yiiframew...questUri-detail for details about requestUri.
3

#6 User is offline   YuriKolovsky 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 45
  • Joined: 18-August 09
  • Location:Malaga, Spain

Posted 08 September 2009 - 01:11 PM

thank you phpdevmd

it was very informative (and makes life easier) :)

now i can safely put it in, knowing that im not messing up the whole purpose of the framework.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

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