Best way to override a yii method

Hi,

Whats the best way to override a Yii method without doing the following …

  1. Changing the method itself in the core Yii folder, this is the "yii" folder which is downloaded from the Yii website.

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

I had a similar Problem and Class Map was the solution.

http://www.yiiframework.com/forum/index.php/topic/13244-showing-message-to-user-before-login/page__view__findpost__p__155406

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?

  1. duplicate the desired class and copy it to your app into /protected/components/ for example.

  2. 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/

:)

[color="#006400"]/* Moved to ‘Tips, Snippets and Tutorials’ */[/color]