【发布时间】:2012-10-20 11:17:05
【问题描述】:
如何获取输入类型文件以验证 cake 中的 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');
【问题讨论】:
标签: cakephp