在CakePHP中,如果我刚刚发布了表单,为什么$ this-> params ['form']为空? [英] In CakePHP, why would $this->params['form'] be empty if I've just posted a form?

查看:54
本文介绍了在CakePHP中,如果我刚刚发布了表单,为什么$ this-> params ['form']为空?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用CakePHP 1.3 ,我发布了一个表格,该表格正确填写了 $ this-> data 。根据文档,它看起来像 $ this-> ; params ['form'] 也应填充一些信息,但这只是一个空数组。 是否有特定原因?

Using CakePHP 1.3, I post a form which correctly fills in $this->data. According to the docs, it seems like $this->params['form'] should be populated with some information as well, but it's simply an empty array. Is there a particular reason for that?

该表单是使用Form Helper构建的,如下所示...

The form is built using the Form Helper, as follows...

$default_form_create_options = array(
    'inputDefaults' => array(
        'label'=>false, 
        'div'=>false
    )
); 

echo $form->create('Preappform', $default_form_create_options);
// --- snip, a bunch of form elements created via $form->input()
echo $form->end(array('label'=>'Send This Form »', 'class'=>'submit-button', 'escape'=>false));

我知道表单数据在 $ this->数据中可用,所以也许这只是一个文档/好奇心问题。如果是这样的话……那太糟糕了。

I know that the form data is available in $this->data, so maybe this is just a documentation/curiosity issue. If so... my bad.

推荐答案

只是咯咯地笑,请尝试 $ this-> params [ '数据'] 。我不知道为什么,但是由于某种原因,它在那里为我显示表单数据。

Just for giggles try $this->params['data']. I don't know why but for some reason it shows form data in there for me.

文档中的数据有冲突,您可以在此处看到 http://book.cakephp.org/view/972/data 。我猜想如果您使用 FormHelper ,它将显示在 $ this-> data 中,如果您不使用 FormHelper ,它将显示在 $ this-> params ['form'] 中。

The documentation has conflicting data as you can see here http://book.cakephp.org/view/972/data. I am guessing that if you use the FormHelper it will show up in $this->data and if you don't use the FormHelper it will show up in $this->params['form'].

请注意,如果您使用 FormHelper ,则元素的名称将为 data ['Model'] ['element_name'] ,并且如果您只是创建您可以手动将其命名为 element_name。通过稍后的操作,我相信它将它放入 params ['form'] 而不是 $ this-> data

Notice if you use FormHelper the name of the element will be data['Model']['element_name'] and if you just create the form manually you can name it 'element_name'. By doing the later I believe it throws it into the params['form'] instead of the $this->data.

这篇关于在CakePHP中,如果我刚刚发布了表单,为什么$ this-> params ['form']为空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆