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.
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,"[]");
}
}
}
?>
Comment