views:

20

answers:

1

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

+1  A: 

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.

Wizzard