extend CWebApplication


I’ve gone through all cookbook articles and docs and just don’t get it - how do I extend CWebApplication?

I have created a new class ‘MyWebApplication’ that extends CWebApplication and stored it in protected/components

I have modified index.php, so it includes my custom yii.php, which extends YiiBase and has createWebApplication overriden:

public static function createWebApplication($config=null)


		return self::createApplication('MyWebApplication',$config);


But now I get this error:

Warning: YiiBase::include(MyWebApplication.php) [function.YiiBase-include]: failed to open stream…

You don’t need to override YiiBase. Why don’t you try this in your index.php?


Great advise, thank you.

It has saved me from YiiBase override, but it still reports the same error.

Should I forcibly include MyWebApplication.php ?

Yes, you should explicitly include this class file because this is more like a bootstrap class.

Just for completeness sake, here is an example of index.php rewritten for a custom app



// remove the following line when in production mode

defined('YII_DEBUG') or define('YII_DEBUG',true);

// Check access



$app = new CMSApplication($config);


But how can i replace CWebApplication in a unit testing ?

application should be instantiated in /protected/tests/bootstrap.php

just create instance of your class same way as in index.php…

ΙΜΗΟ the CWebApplication resembles a lot like a CWebModule so it might be a good idea for a later version of Yii to have even the top level of the application as a module.

I mean to be forced by design like this!

I am not using this approach right now as extensively as I would like due to extensions that have references as ‘application.models…’ or ‘application.controllers…’

How do you think of this idea? :)

I had a case to extend the CWebApplication class but there was a caveat, the $_controller property of CWebApplication is private which must be changed to protected so that someone can extend to have their own version of CWebApplication class.

Ain’t it’s feasible to make all the properties of CWebApplication protected instead of private in the next version of Yii core so that anyone can extend this class easily?