コード例 #1
0
ファイル: Base.php プロジェクト: alanderos/PCD
 public function create($data = null, $whiteList = null)
 {
     if ($result = parent::create($data, $whiteList)) {
         return $result;
     } else {
         foreach ($this->getMessages() as $message) {
             echo $message->getMessage();
         }
         return $result;
     }
 }
コード例 #2
0
 /**
  * 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;
 }