开发者

Why is cakephp form input stored in $this->data and POST data stored in $this->params['form']?

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


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".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜