cakephp behavior validation
I create some Behavior for uploading files... I check rule in Model by methods in Behavior - it's works fine, but i must check is file uploaded (php function: copy() or is_uploaded_file();) and I would like send message to view about this error. How do this?
In your behavior, assuming that you inject the path to the file into the record as 'filename':
function beforeValidate() {
if(!is_file_uploaded($this->data[$this->alias]['filename'])) {
$this->invalidate('filename');
}
return true;
}
精彩评论