Monday, May 14, 2012

Yii current Url

To Get Current Url

echo Yii::app()->request->requestUri;

Get Action Name

//Anywhere
Yii::app()->controller->action->id
//Inside Controller
public function beforeAction($action)
{
    $actionId = $action->id;
    ..........
}

Get Controller Name

// Anywhere
Yii::app()->controller->id 
//Inside Controller echo $this->getId();

2 comments:

  1. //Anywhere
    Yii::app()->controller->action->id
    //Inside Controller
    public function beforeAction($action)
    {
    $actionId = $action->id;
    ..........
    }

    where to write this code??

    ReplyDelete
    Replies
    1. Hi Tushar, Sometimes you want the current controller name or action name. Yii::app()->controller will give the controller name, action name for anywhwere in your application.
      Just echo Yii::app()->controller->action->id or Yii::app()->controller->id any where

      Delete