On Thu, Aug 8, 2013 at 11:54 AM, Philip G <[email protected]> wrote:
> I need some direction as to where I need to go about injecting some code to
> do some dynamic editing of controller return data.
>
> Situation:
>  - Our REST application has the ability to overload the return response
> data to flip between JSON and XML. While we use Accept headers, we default
> to XML return (even if viewed in browser).
>
> I need to capture the array return data from Controller methods
> (AbstractRestfulController) and convert the data to either a View\JsonModel
> or View\XmlModel (custom).
>
> In addition, when converting, I need the View Strategies to trigger. <-

I'd do the following:

- Create renderers specific to the various response types (unless
there are default renderers available)
- Create view models specific to each renderer (unless they already exist)
- Create view strategies that select the appropriate renderer based on
view model (unless one already exists). These strategies should also
have a response listener that injects the content-type.
- Use the AcceptableViewModelSelector controller plugin to retrieve a
view model in your controller, and pass your variables to that: $model
= $this->acceptableViewModelSelector($criteria);
$model->setVariables(/* ... */); return $model;

What this does is ensure that your controller code remains agnostic to
the view layer, while allowing the appropriate renderer to trigger.

Hopefully that makes sense; follow-up if you need more details.


-- 
Matthew Weier O'Phinney
Project Lead            | [email protected]
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

-- 
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]


Reply via email to