get current webpage in yii? how?

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"

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

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

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?

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.yiiframework.com/doc/api/CHttpRequest#requestUri-detail for details about requestUri.

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.