We are going to deploy the new yiiframework.com website on March 23, 2018 from 8:00 to 12:00 UTC.
Website and Yii documentation will not be available in this time frame. Check the news for more details.

Yii 1.1: pisfrontpage

Tells whether the current page is front page or not

That's ought to be one of the smallest Yii extensions around... .


  • Its very common to have some construct in view files along the lines of:
if this is front-page
    print some stuff
end if
  • I wasn't able to find some ready made thing that can tell me just that in Yii so I created this extension.
  • Its a simple behavior component that is attached to the 'web application'.
  • Once attached, it can be used as demonstrated below:
if (Yii::app()->isFrontPage()) {
  // render special widgets, print some stuff, etc...


The requirements are really minimal :) . Just make sure to follow the installation instructions and you're clear for takeoff.


  • Extract the contents of this package. Put the resulted php class file under /protected/components
  • Inside main.php config file:
// ...
'behaviors' => array(
    'isFrontPageTeller' => array(
        'class' => 'application.components.PcIsFrontpage',
// ...
  • That's it! I told you it would be simple.

One last word

I have some doubts that this isn't achievable by other means. Also, maybe you have some reservations on the implementation (the behavior method implementation). In case you have this important feedback please do not spare it from me :) ... (TIA)


Change Log

  • 11 July 2012 v1.1: bugfix: stripping query string from checked url before determining if is front page

Total 5 comments

#10084 report it
Sharkgr8 at 2012/10/03 06:03pm
New and improved extension

New improved extension over this one has been added here http://www.yiiframework.com/extension/pagechecker/

#8942 report it
Boaz at 2012/07/09 08:18am

I see what you mean. The design consideration I described earlier regarding this tiny component feels wrong when put on the same line with the more well known, and much more function-rich app components - is still the same. Further more, AFAIK, even if I did this as an application component:

  • First, it needed to have been an extending of CApplicationComponent and not CComponent (though I might be wrong here).
  • Second, again to to the best of my knowledge, I could not have used it with Yii::app()->isFrontPage() but rather with something like Yii::app()->compName->isFrontPage() which is less desired from the same aesthetic design aspects (which I do not consider mere cosmetics).
#8939 report it
kazio at 2012/07/09 05:45am

but CBehavior extends CComponent and CComponent can be used with Yii::app()->isFrontPage() too.

#8928 report it
Boaz at 2012/07/08 12:59pm

I'm not sure I'm following: why did I made it a CBehavior and not an application component? Because in my humble design eyes this is simpler and more appropriate: A full blown application component looks like an overkill for this task even if Yii manages app components leanly. Can I put on the same line this meager component with other components like urlManager, authManager, db, log, etc... ?

I felt that a mere 1 line(!) behavior class that is easily and intuitively used with Yii::app()->isFrontPage() was a good KISS design.

#8926 report it
kazio at 2012/07/08 10:30am
why ?

why CBehavior not CComponent or even without extend ?

Leave a comment

Please to leave your comment.

Create extension