Example #1
0
 public function actionSalvarRaca()
 {
     $parametros = Util::getParametrosJSON();
     $raca = new Raca();
     $raca->nome = $parametros['nome'];
     $raca->origem = $parametros['origem'];
     $raca->tipoanimalpetshop = $parametros['tipoanimalpetshop'];
     $response = array();
     try {
         if ($raca->save()) {
             $response['sucesso'] = true;
         } else {
             $response['sucesso'] = false;
         }
     } catch (Exception $e) {
         throw new CHttpException(404, $e->getMessage() . '[' . Yii::app()->user->petatual . ']');
     }
     Util::setParametrosJSON($response);
 }
Example #2
0
 /**
  * Action Raca : SAVE
  */
 public function actionSalvarRaca()
 {
     $dadosPost = Yii::app()->request->rawBody;
     $parametros = CJSON::decode($dadosPost, true);
     if (isset($parametros['id']) && $parametros['id'] != '') {
         $raca = Raca::model()->findByPk($parametros['id']);
     } else {
         $raca = new Raca();
     }
     $raca->nome = $parametros['nome'];
     $response = array();
     if ($raca->save() === false) {
         $response['success'] = false;
         $response['errors'] = $raca->errors;
     } else {
         $response['success'] = true;
         $response['raca'] = $raca;
     }
     header('Content-type: application/json; charset=utf-8');
     echo CJSON::encode($response);
     Yii::app()->end();
 }