Announcement

Collapse
No announcement yet.

ORM - Problem with updating Account data via Expo.Ajax.postRequest

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • ORM - Problem with updating Account data via Expo.Ajax.postRequest

    Hi,

    I've problem with my custom controller to update account data via ajax. I'm sending post request by frontend Expo.Ajax.postRequest but there is a problem with saving data by entity manager. Below I attach my code. Everything works except saving entity by ORM. Maybe I should you method $this->getRecordService but I don't know how to set and save new data using this way. Thanks for help.

    PHP Code:
    <?php
    namespace Espo\Custom\Controllers;
    use 
    Espo\ORM\Entity;

    class 
    Geocode extends \Espo\Core\Templates\Controllers\Base {

        public function 
    postActionGeoUpdate($params$data$request) {
            
    $lat explode("=",$params['lat']);
            
    $lon explode("=",$params['lon']);
            
    $uid explode("=",$params['id']);

            
    $entityManager $this->getEntityManager();

            
    $account $entityManager->getRepository('Account')->where(['id' => $uid[1]])->findOne();
            
    // $account = $entityManager->getEntity('Account', $uid); This way also I get NULL 

            
    $account->set('lat'$lat[1]);
            
    $account->set('lon'$lon[1]);

            
    $updateQry $entityManager->getRepository('Account')->save($account);
            if (
    $updateQry == true) {
                
    $status = array("status" => "true");
                
    $json json_encode($status);
                  return 
    trim($json,"[]");
            }
        }
    }
    ?>
    Last edited by jakub.skowron; 02-07-2020, 09:13 AM.

  • #2
    This works now, but I think it's not perfect way to resolve that problem.

    PHP Code:
    <?php
    namespace Espo\Custom\Controllers;
    use 
    Espo\ORM\Entity;
    use 
    \PDO;
    class 
    Geocode extends \Espo\Core\Templates\Controllers\Base {

        public function 
    postActionGeoUpdate($params$data$request) {
            
    $lat explode("=",$params['lat']);
            
    $lon explode("=",$params['lon']);
            
    $uid explode("=",$params['id']);

            
    $entityManager $this->getEntityManager();

            
    $sql " UPDATE account SET
                     lon='"
    .$lon[1]."',
                     lat='"
    .$lat[1]."'
                     WHERE id='"
    .$uid[1]."'
                   "
    ;

            
    $entityManager->runQuery($sql);

            
    $status = array("status" => "true""data" => $lat[1]."::".$lon[1]."::".$uid[1]);
            
    $json json_encode($status);
            return 
    trim($json,"[]");
        }
    }
    ?>
    Last edited by jakub.skowron; 02-07-2020, 10:46 AM.

    Comment

    Working...
    X