开发者

CakePHP: help me with error validate ( why error is miss field when data have that field )

开发者 https://www.devze.com 2023-01-20 13:33 出处:网络
Gallery model var $validate = array( \'id\' => array(\'rule\' => \'numeric\', \'required\' => true, \'allowEmpty\' => false, \'on\' => \'update\'),

Gallery model

var $validate = array(
          'id' => array('rule' => 'numeric', 'required' => true, 'allowEmpty' => false, 'on' => 'update'),
          'name' => array('rule' => 'notEmpty', 'required' => true, 'allowEmpty' => false, 'on' => 'create'),
          'model' => array('rule' => 'notEmpty', 'required' => true, 'allowEmpty' => false, 'on' => 'create'),
          'model_id' => array('rule' => 'numeric', 'required' => true, 'allowEmpty' => false, 'on' => 'create'),
          'status' => array('rule' => array('inList', array('Draft', 'Publish')), 'message' => 'FAILED', 'allowEmpty' => false)
      );

action controller

  private function admin_edit() {
        if (!empty($this->data['Gallery']['id'])) {
              debug($this->data);
              if ($this->Gallery->save($this->data)) {

              }
              debug($this->开发者_开发知识库Gallery->invalidFields());

        }
        $this->redirect('/');
  }

This is error , please help me

app\controllers\galleries_controller.php (line 149)
Array
(
    [Gallery] => Array
        (
            [id] => 38
            [name] => Chap 6
            [status] => Publish
        )

)

app\controllers\galleries_controller.php (line 153)
Array
(
    [id] => This field cannot be left blank
)

why it error miss id when data have id field, MODEL dont use behavior, only ContainableBehavior


You shouldn't have validation on your id field... cake handles all that for you automatically...

If the id isn't set then it creates new entry, if it's set it will update.

0

精彩评论

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