/**
  * API Method inserts a new Cliente record and render response as JSON
  */
 public function Create()
 {
     try {
         $json = json_decode(RequestUtil::GetBody());
         if (!$json) {
             throw new Exception('The request body does not contain valid JSON');
         }
         $cliente = new Cliente($this->Phreezer);
         // TODO: any fields that should not be inserted by the user should be commented out
         // this is an auto-increment.  uncomment if updating is allowed
         // $cliente->Id = $this->SafeGetVal($json, 'id');
         $cliente->Nome = $this->SafeGetVal($json, 'nome');
         $cliente->Telefone = $this->SafeGetVal($json, 'telefone');
         $cliente->Email = $this->SafeGetVal($json, 'email');
         $cliente->Referencia = $this->SafeGetVal($json, 'referencia');
         $cliente->Tipo = $this->SafeGetVal($json, 'tipo');
         $cliente->Docreceitafederal = $this->SafeGetVal($json, 'docreceitafederal');
         $cliente->Enderecos = $this->SafeGetVal($json, 'enderecos');
         $cliente->Validate();
         $errors = $cliente->GetValidationErrors();
         if (count($errors) > 0) {
             $this->RenderErrorJSON('Please check the form for errors', $errors);
         } else {
             $cliente->Save();
             $this->RenderJSON($cliente, $this->JSONPCallback(), true, $this->SimpleObjectParams());
         }
     } catch (Exception $ex) {
         $this->RenderExceptionJSON($ex);
     }
 }
    $cliente->email = get_filter('email');
    $cliente->endereco = get_filter('endereco');
    $cliente->complemento = get_filter('complemento');
    $cliente->bairro = get_filter('bairro');
    $cliente->cep = get_filter('cep');
    $cliente->telefone_fixo = get_filter('telefone_fixo');
    $cliente->telefone_celular = get_filter('telefone_celular');
    $cliente->responsavel = get_filter('responsavel');
    $cliente->pai = get_filter('pai');
    $cliente->telefone_pai = get_filter('telefone_pai');
    $cliente->email_pai = get_filter('email_pai');
    $cliente->mae = get_filter('mae');
    $cliente->telefone_mae = get_filter('telefone_mae');
    $cliente->email_mae = get_filter('email_mae');
    $cliente->observacao = get_filter('observacao');
    $update = $cliente->Save();
    if ($update == 1) {
        echo json_encode(['success' => true]);
    } else {
        echo json_encode(['error' => 'true']);
    }
}
//ação de deletar cliente
if ($action == 'delete') {
    $cliente->id = get_filter('id');
    $delete = $cliente->Delete();
    if ($delete == 1) {
        echo json_encode(['success' => true]);
    } else {
        echo json_encode(['error' => 'true']);
    }
 public function actionDatos()
 {
     $model = new Pedido();
     if (Yii::app()->user->getState('pedido')) {
         $model = Yii::app()->user->getState('pedido');
     }
     if (isset($_POST['Pedido'])) {
         $model->attributes = $_POST['Pedido'];
         if ($model->validate()) {
             if (!($model_cliente = Cliente::model()->findByPk($model->IdCliente))) {
                 $model_cliente = new Cliente();
                 $model_cliente->IdCliente = $model->IdCliente;
                 $model_cliente->DomicilioFacturacion = $model->DomicilioEnvio;
                 $model_cliente->CPFacturacion = $model->CPEnvio;
                 $model_cliente->PoblacionFacturacion = $model->PoblacionEnvio;
                 $model_cliente->ProvinciaFacturacion = $model->ProvinciaEnvio;
                 $model_cliente->Save();
             }
             if ($model->save()) {
                 if (Yii::app()->user->getState('carrito')) {
                     $productos = Yii::app()->user->getState('carrito');
                     foreach ($productos as $model_linea) {
                         $model_linea->IdLinea = null;
                         $model_linea->IdPedido = $model->IdPedido;
                         $model_linea->Save();
                     }
                     unset(Yii::app()->user->carrito);
                     unset(Yii::app()->user->pedido);
                     $this->redirect(array('view', 'id' => $model->IdPedido));
                 }
             }
         }
     }
     $this->render('datos', array('model' => $model));
 }