开发者

cakephp behavior validation

开发者 https://www.devze.com 2023-03-07 06:18 出处:网络
开发者_StackOverflowI 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_uploade
开发者_StackOverflow

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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消