2

I implemented a RESTful application with Zend_Rest that saves info in a mysql db.
I'm going to handle the view with Backbone.js.

I'm looking for just a simple CRUD example. How to do that?

I didn't found any examples with Zend_Rest+Backbone, and the idea is to create it here, together.

UPDATE 0.1

How can I send (from backbone) and read (in the get/put/delete controller) the parameters?

CONTROLLER (modules>api>controllers>BackboneController.php)

class Api_BackboneController extends Zend_Rest_Controller
{
    public function init(){
        $this->_helper->layout->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);
    }
    public function headAction(){
        $this->getResponse()->setBody(null);
    }
    public function optionsAction(){
        $this->getResponse()->setBody(null);
        $this->getResponse()->setHeader('Allow', 'OPTIONS, HEAD, INDEX, GET, POST, PUT, DELETE');
    }   

    // called from backbone with "read"
    public function indexAction(){
        // get the params
        $resp = json_decode(file_get_contents('php://input'));
        // send the same response
        $this->getResponse()->appendBody(json_encode($resp));
    }

    // I can't reach this one from backbone, WHY?
    public function getAction(){}
    // called from backbone with "update"
        public function putAction(){}   
    // called from backbone with "delete"
        public function deleteAction(){}
}

VIEW (modules>default>views>scripts>index.phtml)

var MyModel = Backbone.Model.extend({   
    defaults: {   
        text: "default text"   
    },
    url: "/base/api/backbone",
    options: {
        success: function(data){
            console.log(data);
        },
        error: function(x, t, e){
            console.log("error: " + t + ", " + e);
        }
    }
});

var myModel = new MyModel();  
Backbone.sync("read", myModel, myModel.options);

})(jQuery);
mtoninelli
  • 686
  • 1
  • 6
  • 21
  • The intent of StackOverflow is not to have people do your work for you. You should try making an implementation and then asking questions around specific problems you are having. – Mike Brant Mar 27 '13 at 23:31
  • you're right Mike. I'll add what I did and what I can't do. – mtoninelli Mar 27 '13 at 23:33

0 Answers0