If You want to check the current page, ie action is the default of the current controller..
$controller = Yii::app()->getController();
$isHome = $controller->action->id === $controller->defaultAction->id ? true : false;
dafeultaction may not always be 'index', it can be changed, so you
need to compare it with defaultAction instead..
And by homepage if you mean the defult page of site, then you need to compare your controller also with defaultController
..
$controller = Yii::app()->getController();
$default_controller = Yii::app()->defaultController;
$isHome = (($controller->id === $default_controller->id) && ($controller->action->id === $controller->defaultAction->id)) ? true : false;
In Yii2:
$controller = Yii::$app->controller;
$default_controller = Yii::$app->defaultRoute;
$isHome = (($controller->id === $default_controller) && ($controller->action->id === $controller->defaultAction)) ? true : false;
$controller = Yii::app()->getController(); $isHome = $controller->action->id === $controller->defaultAction ? true : false;
– Oca