I created a component class Comp extends CApplicationComponent
and define it in main.php
Presently I am passing value to its constructor
as
$comp = new Comp($value);
.
Is it possible to call its constructor using Yii::app()->comp
?
I created a component class Comp extends CApplicationComponent
and define it in main.php
Presently I am passing value to its constructor
as
$comp = new Comp($value);
.
Is it possible to call its constructor using Yii::app()->comp
?
There is no convenient way of doing this in Yii 1.1 - every component should be instance of IApplicationComponent
with configuration in public properties and actual initialization in init()
. That is why there is so many Yii extensions which are simple wrappers for generic PHP libraries - you need to create such wrapper for each class which does not follow Yii convention for defining components.
Once you autoload it in config/main.php you can use the component anywhere in the application (controller or module)
In your config.main add in the array 'components' the class that you want somethign like this:
'clientScript' => [
'class' => "ext.ClientScript.ClientScriptManager"
],
Where 'ext' is "protected/extension' and the 'ClientScript' is the name of the folder and the 'ClientScriptManager' is name of the class.