Cakephp Formhelper:禁用文本区域所需的

Cakephp Formhelper : disable required on textarea

我试图在我的表单中禁用该文本输入的必填项。 然而,即使
['required' => false], ['allowEmpty' => true] 从 HTML 中删除 "required=required",当我尝试将其设为空时,我仍然会收到 'This field cannot be left empty'。

据我所知,此字符串位于 Validator.php 中,但即使我尝试编辑或删除我认为导致此问题的内容,我也没有找到解决办法。 我正在使用 cakephp 3.0.2 这是我的小表格:

<?php
echo $this->Form->create($schedule);
echo $this->Form->input('year', [array('type' => 'text', 'readonly' => 'readonly')]);
echo $this->Form->input('month',[array('type' => 'text', 'readonly' => 'readonly')]);
echo $this->Form->input('text', ['required' => false], ['allowEmpty' => true]);
echo $this->Form->button(__('Save'));
echo $this->Form->end();
?>

谢谢你给我时间。

您的模型是如何定义的?你有

public $validate = array()

定义?你确定你没有在那里设置 required=true ,你在那里设置了 'allowEmpty => true 吗?因为那是验证所属的地方而不是在表单中,所以你应该首先检查你没有自相矛盾。