我有一个用户可以上传图像的表单,我将它打印到页面上,如下所示:
<?php echo $this->Form->label('file', 'Image file', array('class' => 'col-lg-1 control-label')); ?>
然后,在模型中,我正在设置验证,如下所示:
public $validate = array(
'file' => array(
'required' => array(
'rule' => array('notEmpty'),
'message' => 'You must select an image to upload'
),
'extension' => array(
'rule' => array('extension', array('png')),
'message' => 'Images must be in PNG format'
),
'size' => array(
'rule' => array('fileSize', '<', '1MB'),
'message' => 'Images must be no larger than 1MB'
),
'goodUpload' => array(
'rule' => 'uploadError',
'message' => 'Something went wrong with the upload, please try again'
)
)
);
但是,Cake 似乎没有将表单字段与验证规则相关联,就好像我选择要上传的图像一样,我总是收到“您必须选择要上传的图像”作为表单错误。我已经确定表格有enctype="multipart/form-data"
.
发生这种情况是因为file
不是数据库字段吗?我怎样才能让蛋糕运行一些验证file
?
编辑:这是我的整个表格,根据要求: http: //pastebin.com/SbSbtDP9