1
如何獲得輸入類型文件來驗證蛋糕中的notempty?cakephp文件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');