cakephp验证问题:分隔符不能是字母数字或反斜杠

Phi*_*hil 10 php cakephp

我刚刚开始使用CakePHP,我遇到了这个问题

Warning (2): preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash [CORE/cake/libs/model/model.php, line 2611]

当我尝试添加/编辑帖子时,我明白了.这个验证码会触发它:

var $validate = array(
        'title' => array(
            'title_not_blank' => array(
                'rule' => 'nonEmpty',
                'message' => 'This post is missing a title'
            ),
            'title_unique' => array(
                'rule' => 'isUnique',
                'message' => 'A post with this title already exists'
            )
        ),
        'body' => array(
            'body_not_blank' => array(
                'rule' => 'notEmpty',
                'message' => 'Post is missing its body'
            )
        )
    );
Run Code Online (Sandbox Code Playgroud)

我不知道该怎么做?有帮助吗?

YOM*_*les 22

你知道吗?您正在执行验证规则/代码(即使每个字段有多个规则).问题的唯一原因是你在第一个规则中编写nonEmpty而不是notEmpty(注意t).

是的,我知道这些小事情是多么令人沮丧.也许这就是我们编码员最终发展强迫症的原因.:d

  • 不要忘记'notEmpty'已被弃用 - 请改用'notBlank'. (2认同)