How Do I Construct Class As Application Component

This is probably an easy one to figure out for Yii experts, unfortunately I’m a novice, but I love this framework already:

I have put the standard jsonRPCClient.php file into the “components” folder. (you can find the code for it via google, it’s not letting me put a link in here)

Normally I would simply call for example:

$rpcObject = new jsonRPCClient(‘someUrlAndPort’);

This then allows me to run RPC commands on $rpcObject to communicate with the service running on that port on that server, for example:

$someResult = $rpcObject->getSomeResult();

I would like to create an application component in main.php so no matter where I am in Yii I can always call for example:

$someResult = Yii::app()->rpcObject->getSomeResult()

I tried the following in main.php:

‘components’=>array(

	'user'=>array(


		// enable cookie-based authentication


		'allowAutoLogin'=>true,


	),


	...


	'rpcObject'=>array(


		'class'=>'jsonRPCClient',


		'url'=>'someUrlAndPort',


	),


	...





),

But I get the following error report:

Missing argument 1 for jsonRPCClient::__construct(), called in /xxx/yyy/xamppfiles/htdocs/myapp/framework/YiiBase.php on line 217 and defined

So somehow it’s not taking the $url parameter into the constructor.

Any ideas?

Dear Friend

I think you have a constructor function with parameters inside the applicationComponent class.

When configuring the components from main.php, application is not passing the values to these parameters.

These errors occur because of that.

One has to avoid the constructor function when creating application component classes.

This is what YII says…

Regards.

Got it, thanks much!