Search code examples
magentomagento-1.7magento-1.9magento-1.8magento-1.4

redirect to the same page magento without $this


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é !!');
    }


}

Solution

  • 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.