4

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?

rob006
  • 21,383
  • 5
  • 53
  • 74
Lalitesh Upadhyaya
  • 311
  • 1
  • 4
  • 14

3 Answers3

0

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.

rob006
  • 21,383
  • 5
  • 53
  • 74
-1

Once you autoload it in config/main.php you can use the component anywhere in the application (controller or module)

-1

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.

Renziito
  • 78
  • 3