controller function:
public function changeCommercialAction()
{
if ($this->request->isPost()) {
if ($this->request->isAjax()) {
$nc = $this->request->getPost('nc');
$id = $this->request->getPost('id');
$commercial = Commerciaux::findFirst("nomCommercial = '$nc'");
if (!$commercial) {
$messageCommercial = "commercial not found";
} else {
$messageCommercial = "commercial saved";
$commercialID = $commercial->id;
$Newdevi = Devis::findFirstByid($id);
$Newdevi->commercialID = $commercialID;
if ($Newdevi->update() == false) {
$messageDevis = "le commercial n'a pas été mis à jour";
}
else {
$lastInsertId = $this->db->lastInsertId();
$messageDevis = 'lastInsertId :' . $lastInsertId;
}
}
$this->view->messageCommercial = $messageCommercial;
$this->view->messageDevis = $messageDevis;
}
}
}
ajax response:
{"title":"Devis","messageCommercial":"commercial saved","messageDevis":"lastInsertId :","success":true,"message":"blurp"}