Yii Framework Forum: Service class ? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Service class ? Rate Topic: -----

#1 User is offline   maxmilian 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 25
  • Joined: 30-September 09

Posted 12 March 2010 - 06:47 AM

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
0

#2 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,013
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 12 March 2010 - 06:58 AM

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

#3 User is offline   maxmilian 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 25
  • Joined: 30-September 09

Posted 12 March 2010 - 07:02 AM

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.
0

#4 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,013
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 12 March 2010 - 07:13 AM

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.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users