如何在cakephp 2x中编写多个规则

时间:2017-03-07 06:32:53

标签: php validation cakephp cakephp-2.0

我的问题是当用户发布我想要的新文章时不需要文本字段,但是当用户编辑帖子时我需要文本字段。 我的代码有什么问题

public $validate = [
    'title' => [
        'required' => true,
        'allowEmpty' => false,
        'rule' => ['maxLength','20'],
        'on' => 'create',
        'message' => 'over 20 words'
    ],
    'status' => [
        [
            'rule' => ['maxLength','200'],
            'on' => 'create',
            'message' => 'over 200 words',
            'last' => true,
        ],
        [
            'required' => true,
            'allowEmpty' => false,
            'rule' => ['maxLength','200'],
            'on' => 'update',
            'message' => 'over 200 words',
            'last' => true, 
        ],
    ],  
];

0 个答案:

没有答案