how to check if it is homepage


(Bingjie2680) #1

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.


(Kburton) #2

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.


(Mauglee) #3

In Yii2:


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

	// it is Home page

}