Hi,
Whats the best way to override a Yii method without doing the following …
-
Changing the method itself in the core Yii folder, this is the "yii" folder which is downloaded from the Yii website.
-
Alter the original class name of the overridden method.
Basically I need to alter a method within CGridView, but it still needs to work exactly like CGridView.
Could possibly change the class name to like "CGridViewExt" if absolutely nessacary, but is there a way to do it without changing anything?
Any ideas anyone? This one is really important one for me.
Like I say, I can change the class name if absolutely necessary.
I just want to override a CGridView method without altering the core yii files, anyone know how?
So I can call it like …
zii.widgets.grid.CGridViewExt
Rather than …
zii.widgets.grid.CGridView
James.
natter
(Gernatter)
3
Hi,
Thanks.
Ok and where do I put this code …
Yii::$classMap=array(
'CAccessControlFilter' => dirname(__FILE__).'/protected/components/CAccessControlFilter.php',
);
Yii::createWebApplication($config)->run();
In what files and in what place.
And do I need to copy the class I want to override the method in or do I just extend the class or something?
beatmox
(E Kie)
5
-
duplicate the desired class and copy it to your app into /protected/components/ for example.
-
edit your bootstrap aka index.php and make sure u map the class before
Yii::createWebApplication($config)->run();
Yii::$classMap=array(
'CGridView' => dirname(__FILE__).'/protected/components/CGridView.php',
);
Yii::createWebApplication($config)->run();
documented and discussed @:
http://www.yiiframework.com/doc/guide/1.1/en/basics.namespace#importing-classes
http://www.yiiframework.com/forum/index.php/topic/28979-how-to-override-yii-core-classes/

jacmoe
(Jacob Moena)
6
[color="#006400"]/* Moved to ‘Tips, Snippets and Tutorials’ */[/color]