Overriding Yii class


Current implementation of Yii class is empty and it extends YiiBase class.

So if I want to override default implementation of some static methods (i.e. createComponent, t or createWebApplication) I may go two ways:


[*]Declare class with name different to Yii (f.e. YiiEx) inherited from YiiBase

[*]Declare my own Yii class which overrides methods and use it instead of standard Yii class.


First aproach is not very convinient because there are written a lot of code uses Yii class name.

The second one works well but I am having problems using classes from yiilite.php. This file contains empty implemetation of default Yii class. When I am trying to use my own implementation of Yii class PHP fires an error which says that class is already defined.

For now I’ve delete default Yii class from yiilite.php to get my project working fine.

What could you advice me in this case?

P.S. What if I will generate my own yiilite.php during deployment process?

You shouldnt modify yiilite.php you can supply for example your own application class that extends CWebApplication in the index.php.

Within the config.php you can specify your own specialized classes for all other purposes. For example request handling, session handling etc.

I see that. My question is am I able to override default Yii class? If answer is yes then what is the best way to do it (replace it with my own Yii class or inherit from it)

Regarding to Yii class documentation:

… so, I am allowed to define my own Yii class. Could somebody answer my original question?

Yes, you can define your own Yii class by extending from YiiBase.

To do so, simply copy yii.php, modify it and include it in your bootstrap file.

Thank you for reply, Qiang!

But I asked a bit another question in first post in this topic.

Default Yii class (an empty one) is already defined in yiilite.php

And when I try to declare my own implementation of Yii, I get error regarding already defined class.

But how then should I redefine Yii class and keep yiilite.php in use?

Or how can I use my own implementation of Yii without having to change yiilite.php?

yiilite.php is a compact version of yii.php + YiiBase.php + Yii core component.

So you can not use yiilite.php and yii.php in the same time.

There is a "class Yii extends YiiBase" definition in yiilite.php.

You can find at line 463 of it, if you want to override yii class.

Thank you for reply