Yii Framework Forum: how to check if it is homepage - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

how to check if it is homepage Rate Topic: -----

#1 User is offline   bingjie2680 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 56
  • Joined: 08-June 11

Posted 01 March 2012 - 11:16 AM

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.
0

#2 User is offline   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,707
  • Joined: 04-March 10
  • Location:UK

Posted 01 March 2012 - 11:26 AM

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.
1

#3 User is offline   Maug Lee 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 21-June 12
  • Location:Lithuania

Posted 20 June 2018 - 03:21 AM

In Yii2:
if ( Url::toRoute( Url::home() ) == Url::toRoute( Yii::$app->controller->getRoute() ) ) {
	// it is Home page
}

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users