kvz / cakephp-rest-plugin

Discontinued: recent cakephp versions overlap functionality, there also is @ceeram's plugin. Painless REST server Plugin for CakePHP
http://kvz.io/blog/2010/01/13/cakephp-rest-plugin-presentation/
169 stars 37 forks source link

Minor addition to _modelizePost #13

Closed m3nt0r closed 13 years ago

m3nt0r commented 13 years ago

When posting an CakePHP-Form the data already is modelized, but _modelizePost is not aware of that.

The way it was Set::countDim returns 2, but $this->numeric would not find any numeric keys. That raised the "2 dimensional can only begin with numeric index" error even though everything should be running smoothly.

Example form: $this->Form->create('Post', array('id' => 'rest')); $this->Form->input('foo', array('value' => 'bar'); $this->Form->end('Submit');

Example post: $.ajax('/posts.json', { type: 'POST', data: $('#rest').serialize(), success: function(r){ console.log(r); } });

Example input: $data['Post'] = array( 'foo' => 'bar' );

So to overcome this problem i just de-modelize the array, if className-key is present, before the countDim test.

$data = array( 'foo' => 'bar' );

Should work just fine without hurting existing functionality.