如何获取输入类型文件以验证蛋糕中的 notempty?
当您提交表单而不添加文件时,即使 $this->request->data 显示该文件,验证也会显示它为空。
// 模型/Product.php
class Product extends AppModel {
public $validate = array(
'name' => array(
'rule' => 'notEmpty'
),
);
}
// 控制器/ProductController.php
public function add() {
if ($this->request->is('post')) {
$this->Product->create();
if ($this->Product->save($this->request->data)) {
$this->Session->setFlash('Your product has been saved.');
} else {
$this->Session->setFlash('Unable to add your product.');
debug($this->request->data);
debug($this->Product->validationErrors);
}
}
}
// 查看/产品/add.ctp
echo $this->Form->create('Product', array('type' => 'file'));
echo $this->Form->input('name', array('type' => 'file'));
echo $this->Form->end('Save Post');