0

我正在应用程序的布局中创建表单,并且视图只有输入。

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

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

有没有办法像 inputDefaults 一样在我的视图中设置默认模型

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

Cake Validation 仅在使用 [modelname][fieldname] 找到输入时才有效,因此我可以在视图中写入

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

但我必须改变我所有的形式。

有什么办法可以在视图中设置模型名称?

4

1 回答 1

0

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:

$this->Form->create('specficmodelname');
于 2013-06-09T08:56:36.587 回答