Service class ?


(Andreas Strahle) #1

Hi all !!

Coming from the Java world I would like to implement a service layer between the controllers and the models.

eg in the controller i would like to do something like this.

in the controller




	public function actionTest($articleId, $endCustomer, $reseller){


		$hwService = new HwService();

		$hwQoutes = $hwService->gethwPrice( $articleId, $endCustomer, $reseller );

		$this->render('list',array(

			'hwQoutes'=>$hwQoutes 

		));


		

	}



However I have some troubles I have added a "service" folder in the protected folder.

This folder conatains the hwservice class and I have added the service folder to the import array in config

But when instancing the hwservice class from a controller I get Missing argument 1 for CController…

what Im a missing here ?

Thanks in advance


(Mh) #2

How did you define your HwService class? Is it extended from CController? If so, why? If not, what is the constructor for that class?


(Andreas Strahle) #3

ohh man I am such noob with PHP, Im used to have a default constructor by default …

Now its working thanks for kicking me in the right direction.


(Mh) #4

No problem. You might also consider to let your service extend from CApplicationComponent. Then you can configure it like any other Yii component in main.php. To access it, you’d use e.g Yii::app()->hwService.