Last active
December 14, 2015 12:59
-
-
Save crisu83/5090534 to your computer and use it in GitHub Desktop.
Random thoughts about using namespacing for the HTML helper in Yiistrap.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* Core implementation */ | |
| // Helper | |
| namespace bootstrap\helpers; | |
| class Html extends \CHtml { | |
| public static function someStaticHelperMethod() { | |
| // core implementation | |
| } | |
| } | |
| // Active form | |
| use bootstrap\helpers\Html; | |
| class TbActiveForm extends CActiveForm { | |
| function someMethod() { | |
| return Html::someStaticHelperMethod(); // calls the core implementation | |
| } | |
| } | |
| /* Custom implementation */ | |
| // Helper | |
| namespace app\helpers; | |
| class Html extends \bootstrap\helpers\Html { | |
| public static function someStaticHelperMethod() { | |
| // overridden method | |
| } | |
| } | |
| // Active form | |
| use app\helpers\Html; | |
| class ActiveForm extends TbActiveForm { | |
| function someMethod() { | |
| return Html::someStaticHelperMethod(); // calls the overridden method | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment