Using core classes override? Example?

I am trying to use a feature introduced in version 1.1.9 but can’t figure out the correct way:

I have this fragment:







Yii::$classMap = array(

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

);

$app = Yii::createWebApplication($config);

$app->run();



and the class is in my components folder

for now only:




class PortalWebApplication extends CWebApplication {

    

}

I can’t get this to work because it tells me Class ‘CWebApplication’ not found.

But how to import and override the class from the framework?

I don’t see how I can extend CWebApplication to override one single function only, and reuse anything else.

[b]

[/b]

What I see is that I must duplicate the whole code from the core class.




require 'path/to/PortalWebApplication.php';

Yii::createApplication('PortalWebApplication', $config)->run();



I think this new feature was introduced for some special use cases, eg. when you need to fix an issue in the framework and can’t wait for the next release. You usually don’t have to use it when you want to extend framework classes.

No. :)

Tell Yii to import the code:


Yii::import('web.CWebApplication');

Put that before your derived class. ;)

Uncaught exception ‘CException’ with message 'Alias “web.CWebApplication” is invalid.

Try ‘system.web.CWebApplication’

Sounds like you’re just trying to extend CWebApplication, that feature is meant to whole hog replace core classes, not override them.

If I understood your goal, what you need to do is use:


Yii::createApplication('PortalWebApplication', $config)->run();

in your index.php instead of the current


Yii::createWebApplication($config)->run()

.