0

If I build a custom API (class) and want to pass the values obtained from an API call to my controller, how do I do that? Usually I have do this in my controller:

$form = new Application_My_Form();
$model = new Application_My_Model($form->getValues());

But since I'm not using a form and there isn't a view, then how do I post/pass the values from my API to the controller's action? Is there a better way to pass an array of values from my API class to a controller?

ews2001
  • 2,176
  • 3
  • 26
  • 38

1 Answers1

0

So your API is built within your ZF application? And you are within the controller for your API? You can access input parameters using

$params = $this->getRequest()->getParams();

which will give you an associative array of supplied parameters.

ChrisA
  • 2,091
  • 1
  • 14
  • 23
  • I have the API class in my Zend application custom library. I'm not within the controller, but trying to pass values from my API class to a Zend controller. Thanks for supplying the statement to use within my controller, now, what would the statement look like in the API class? How do I pass those "params" from the class to the controller? – ews2001 Jun 28 '12 at 15:37
  • From outside the controller, you can use `Zend_Controller_Front::getInstance()->getRequest()->getParams();`, if you need to pass values from API to controller, then just make them available via the instance of the API class you have in your controller? – ChrisA Jun 28 '12 at 16:13
  • Sorry, I'm probably not explaining this correctly...I think I have a grasp now on how to get the params in my controller - as you pointed out `$params = $this->getRequest()->getParams();` But now how do I "set" the params in the api class so that they're available to grab? – ews2001 Jun 28 '12 at 18:06
  • Is this what I need to use? `$this->getRequest()->setParams($values);` – ews2001 Jun 29 '12 at 04:50