简体   繁体   English

Cakephp表单助手模型

[英]Cakephp form helper Model

I am creating my form in the layout of my application and the view just have inputs. 我在应用程序的布局中创建表单,而视图仅包含输入。

// In layout
$this->Form->create('modelname');

// In view
$this->Form->input('fieldname');

Is there a way I can set default Model in my view just like inputDefaults 有没有办法像输入默认值一样在视图中设置默认模型

$this->Form->inputDefaults(array(
     'label' => false,
    'div' => false,
    'class' => 'fancy'
)
); 

Cake Validation only works if it found input using [modelname][fieldname], so I can write in the view Cake Validation仅在使用[modelname] [fieldname]找到输入时才起作用,因此我可以在视图中编写

 $this->Form->input('modelname.fieldname');

but I have to change all of my forms. 但我必须更改所有表格。

Is there any way I can set model name in the view?? 有什么办法可以在视图中设置模型名称?

Why the .... are you creating your form in the layout?? 为什么……在布局中创建表格? This is very wrong unless there is some great reason for it (and I cannot see no such reason): 除非有充分的理由,否则这是非常错误的(并且我看不到任何此类原因):

// In layout
$this->Form->create('modelname');
// In view
$this->Form->input('fieldname'); 

You should create separate forms in each view there is a form. 您应该在每个视图中创建一个单独的表单。 Since each form is tied to a different model. 由于每种形式都绑定到不同的模型。 Your validation is not working without modelname.fieldname since every form in every view does not attach itself to the right Model... You should creare every form in every view with: 没有modelname.fieldname您的验证将无法正常进行,因为每个视图中的每个表单都无法将自身附加到正确的模型上。您应该使用以下方法创建每个视图中的每个表单:

$this->Form->create('specficmodelname');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM