/**
  * Save/Create/Update an object
  *
  * @param  \Phalcon\Mvc\Model $object
  * @param  string             $type
  * @throws \Exception
  * @return Object
  */
 public function save($object, $type = 'save')
 {
     switch ($type) {
         case 'save':
             $result = $object->save();
             break;
         case 'create':
             $result = $object->create();
             break;
         case 'update':
             $result = $object->update();
             break;
     }
     if (false === $result) {
         foreach ($object->getMessages() as $message) {
             $error[] = (string) $message;
         }
         $output = count($error) > 1 ? json_encode($error) : $error[0];
         throw new \Exception($output);
     }
     return $object;
 }
Example #2
0
 /**
  * @param Model $item
  * @param $data
  *
  * @return Model Updated model
  */
 protected function updateItem(Model $item, $data)
 {
     $item->assign($data);
     $success = $item->update();
     return $success ? $item : null;
 }
 public function update($data = null, $whiteList = null)
 {
     $this->_isNew = false;
     return parent::update($data, $whiteList);
 }