That's ought to be one of the smallest Yii extensions around... .
General ¶
- 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:
<?php
if (Yii::app()->isFrontPage()) {
// render special widgets, print some stuff, etc...
}
?>
Requirements ¶
The requirements are really minimal :) . Just make sure to follow the installation instructions and you're clear for takeoff.
Installation ¶
- 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)
Resources ¶
Change Log ¶
- 11 July 2012 v1.1: bugfix: stripping query string from checked url before determining if is front page
why ?
why CBehavior not CComponent or even without extend ?
@kazio
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.
ok
but CBehavior extends CComponent and CComponent can be used with Yii::app()->isFrontPage() too.
@kazio
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:
New and improved extension
New improved extension over this one has been added here
http://www.yiiframework.com/extension/pagechecker/
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.