Jump to content


Photo

Api Create Account-Save to DB

api account create save database

  • Please log in to reply
No replies to this topic

#1 Zurmo User

Zurmo User

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 05 June 2014 - 09:46 AM

Hi,

 

I'm new to Zurmo and I'm trying to create a new account using Api create new account. I followed all the instructions in this documentation:

http://zurmo.org/wik...cation-accounts

 

I just need to save the result to my database. Here is my code:

 

 protected function processCreate($data,$id)
        {
            $modelClassName = $this->getModelName();
            try
            {   if (isset($data['modelRelations']))
                {
                    $modelRelations = $data['modelRelations'];
                    unset($data['modelRelations']);
                }
                
                $tableName = $modelClassName::getTableName();
                $beans = ZurmoRedBean::find($tableName, "mobile_id = '$id'");
                if (count($beans) > 0)
                {
                    $message = Zurmo::t('ZurmoModule', 'This id is already exist in our records...');
                    throw new ApiException($message);
                }
            
                $model = new $modelClassName();
                $data['mobile_id']=$id;
                
             
                $model = $this->attemptToSaveModelFromData($model, $data, null, false);
              
                $model->forget();
                if (!count($model->getErrors()))
                {
                    if (isset($modelRelations) && count($modelRelations))
                    {
                        try
                        {
                            $this->manageModelRelations($model, $modelRelations);
                            $model->save();
                        }
                        catch (Exception $e)
                        {
                            $model->delete();
                            $message = $e->getMessage();
                            throw new ApiException($message);
                        }
                    }
                
                    $data   = static::getModelToApiDataUtilData($model);
                    $result = new ApiResult(ApiResponse::STATUS_SUCCESS, $data, null, null);
                }
                else
                {
                    $errors = $model->getErrors();
                    $message = Zurmo::t('ZurmoModule', 'Model was not created.');
                    $result = new ApiResult(ApiResponse::STATUS_FAILURE, null, $message, $errors);
                }
            }
            catch (Exception $e)
            {
                $message = $e->getMessage();
                throw new ApiException($message);
            }
            return $result;
        }
 
 
How can I save the returned result to my database??
I know my question may seem trivial but I really need your help :(
 
Thank you.
 






Also tagged with one or more of these keywords: api, account, create, save, database

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users