Best way to override a yii method


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 …


Rather than …



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



Ok and where do I put this code …


    'CAccessControlFilter' => dirname(__FILE__).'/protected/components/CAccessControlFilter.php',



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



    'CGridView' => dirname(__FILE__).'/protected/components/CGridView.php',



documented and discussed @:


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