in my model i have some function() and i call it when i submit my form, so in this function() i do some write query and i want to display a succes message Mage::getSingleton('adminhtml/session')->addSuccess('Ok !');
if the data are uploaded else i display a error message Mage::getSingleton('adminhtml/session')->addError('KO !');
but in the same page. i tried to to do $this->_redirectReferer(); but i have an error.
function() in model
public function setTestimony($name, $testimony, $image_url, $vendor_id, $is_active) {
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
if ($name != "" && $testimony != "" && $vendor_id !="" && $is_active != "" ) {
$insert = "INSERT INTO wlc_testimony (`name`, `testimony`, `image_url`, `vendor_id`, `is_active`)
VALUES ('$name', '$testimony', '$image_url', '$vendor_id', '$is_active')";
$write->query($insert);
$this->_redirectReferer();
Mage::getSingleton('adminhtml/session')->addSuccess('Témoignage ajouté !');
}else{
$this->_redirectReferer();
Mage::getSingleton('adminhtml/session')->addError('Témoignage non ajouté !!');
}
}
Redirection from a model's method is not a best way. Request redirection should be performed inside controller's Action method.
$this->_redirectReferer();
Will work on controller not in model.