tags:

views:

239

answers:

1

the cakephp rest tutorial says that post data should be in $this->data, but I am finding that it is not, but instead inside $this->params['form']

However, when using cakephp form helper in a view, the data is in $this->data.

Am I correct to have to check both locations in my controller?

It just seems a bit of a waste of extra code. Shouldnt the data appear in one place for whether it came from a rest rest requestor or Cakephp form post?

ps im using cakephp 1.3

+2  A: 

I think probably the input names in your HTML aren't correct or aren't being generated correctly (if you're using the form helper). Double check your HTML to be sure (view source in a browser).

Data stored in Controller::data variable comes from POST values where the input's name starts with data. So this input tag will have the value in $this->data['Anything']['Something']:

<input type="text" name="data[Anything][Something]" />

When you use the form helper, and do this:

<?php echo $form->input( 'Something' ); ?>

The form helper is smart enough to know which model you're using (I think because it sets an attribute when you call $form->create('Modelname')). So the above (PHP/form helper) example would output:

<input type="text" name="data[Modelname][Something]" ... />

Of course, there are a few caveats (Modelname.Something must be a field that exists in the corresponding database table), but you can learn more by looking at the manual.

And finally, I believe the $this->params['form'] attribute has all the POSTed values, regardless of whether you prefix the input name with "data".

Travis Leleu
thanks travis for your answer, i have indeed confirmed that cake adds the data name into the generated forms source (which i cant change). But I am not finding that all post data is always put in $this->params. So i am still stuck checking both in controller :-(
DEzra