how to check if it is homepage

I have searched everwhere in this site, could not find a tip for determin whether is on home page, something like is_home(), anybody has ideas? thanks for help.

You could just compare the current controller and action with the default controller and action for your home page.

$controller = Yii::app()->getController();

$isHome = $controller->getId() === ‘home’ && $controller->getAction()->getId() === ‘index’;

There may well be a cleaner way, however.

In Yii2:


if ( Url::toRoute( Url::home() ) == Url::toRoute( Yii::$app->controller->getRoute() ) ) {

	// it is Home page

}