Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm developing a RESTful application on Zend Framework 2 basis. Just implemented the get(...) method of the controller:

class SeminarsController extends RestfulController
{
    /**
     * @var Zend\Db\TableGateway\TableGateway
     */
    private $seminarTable;

    ...

    public function get($id)
    {
        $seminarDetails = $this->getSeminarsTable()->findOnceByID($id)->current();
        return new JsonModel(array('data' => array(
            'id' => $seminarDetails->id,
            'title' => $seminarDetails->title,
            'details' => $seminarDetails->details
        )));
    }

    ...

}

Works fine. But now it's bound to a hard defined output format -- JSON. How can/should I make it more flexible, in order to enable the user/client to get the output in different formats?


EDIT

What I want to know is, what structure/architecture solution for such case(-s). I'm sure, there are best practices / standard solutions for this problem.

share|improve this question

1 Answer

You are looking for a custom view strategy (you can create a custom view strategy to render any kind of response).

There is a great webinar on this by Matthew Weier O'Phinney that you can watch on the Zend website.

If the link doens't work, go to the recorded webinars page and look for "Build RESTful ZF2 Applications".

The webinar contains all information you need including code samples.

share|improve this answer
Thank you for your answer! But what I mean is more the architecture. I'll edit my question, in order to make it clear. – automatix Jun 14 at 16:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.