aaargh... the way I explain things leads to confusion, sorry...so, makin it shorter/simple:
public function createNewBlocAction() {
if ($this->request->isPost()) {
if ($this->request->isAjax()) {
$paramBloc = json_decode($this->request->getPost('paramBloc'));
$checkBlocExist = Blocarticle::findFirst(array( //using here a foreign model (we are in InvoiceController.php)
'columns' => '*',
'conditions' => 'operationID = ?1 AND nomBloc = ?2',
'bind' =>
[
1 => $paramBloc->operationID,
2 => $paramBloc->nomBloc,
]
));
if(!$checkBlocExist) {
$blocArticle = new Blocarticle();
$blocArticle->operationID = $paramBloc->operationID;
$blocArticle->nomBloc = $paramBloc->nomBloc;
$blocArticle->save();
$this->view->messageAddNewBloc = "ok"; /// ----> doesn't work, ajax response always empty, and in Db, $blocArticle have been correctly saved
}
else {
$this->view->messageAddNewBloc = "bad";
}
}
}
}
ajax response : {"title":"Devis","success":true,"message":""}
the same, removing the 'save' op:
public function createNewBlocAction() {
if ($this->request->isPost()) {
if ($this->request->isAjax()) {
$paramBloc = json_decode($this->request->getPost('paramBloc'));
$checkBlocExist = Blocarticle::findFirst(array( //using here a foreign model (we are in InvoiceController.php)
'columns' => '*',
'conditions' => 'operationID = ?1 AND nomBloc = ?2',
'bind' =>
[
1 => $paramBloc->operationID,
2 => $paramBloc->nomBloc,
]
));
if(!$checkBlocExist) {
$blocArticle = new Blocarticle();
$blocArticle->operationID = $paramBloc->operationID;
$blocArticle->nomBloc = $paramBloc->nomBloc;
// $blocArticle->save(); we bypass the save operation
$this->view->messageAddNewBloc = "ok"; /// ----> is workin correctly, ajax response not empty
}
else {
$this->view->messageAddNewBloc = "bad";
}
}
}
}
ajax response : {"title":"Devis","messageAddNewBloc":"ok","success":true,"message":""}