我正在嘗試在文件上傳中使用Cake 2.3.8進行驗證,以確保只能上傳PDF。我懶散地基於這個this教程。用於文件上傳的CakePHP驗證
我的表單在輸入旁邊顯示星號,當我從模型中刪除驗證時,星號消失。我假設這意味着它「看到」驗證的輸入,但我無法弄清楚爲什麼即使自定義驗證沒有被觸發。
這裏的形式
echo $this->Form->create('Upload', array('type' => 'file'));
echo $this->Form->input('file_upload', array('type' => 'file'));
echo $this->Form->input('file_title');
echo $this->Form->end(__('Upload File!', true));
下面是我上傳模型
public function checkUpload(){
echo "test"; //check to see if it reaches this...not displaying
return false; //the error message should be set just for testing, it's not displaying though
}
public $validate = array(
'file_upload' => array(
'extension' => array(
'rule' => array('extension', array('pdf')),
'message' => 'Only pdf files',
),
'upload-file' => array(
'rule' => array('checkUpload'),
'message' => 'Error uploading file'
)
)
);
什麼是某事?我試着完全是這樣的,它說:「使用未定義的常量......假設'......' – user2443591
lol ... sth表示你想調試的東西....在這種情況下,你可以做調試(」這裏「); – Geoffreyirl
你得到這個錯誤意味着你已經輸入了函數checkUpload – Geoffreyirl