【问题标题】:redirect to the same page magento without $this在没有 $this 的情况下重定向到同一页面 magento
【发布时间】:2017-01-02 20:44:44
【问题描述】:

在我的模型中,我有一些函数(),我在提交表单时调用它,所以在这个函数()中我做了一些写查询,我想显示一条成功消息Mage::getSingleton('adminhtml/session')->addSuccess('Ok !'); 如果数据已上传,否则我会显示错误消息Mage::getSingleton('adminhtml/session')->addError('KO !'); 但在同一页面中。我试图做 $this->_redirectReferer();但我有一个错误。

模型中的函数()

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


}

【问题讨论】:

    标签: magento magento-1.7 magento-1.9 magento-1.8 magento-1.4


    【解决方案1】:

    从模型的方法重定向不是最好的方法。请求重定向应该在控制器的 Action 方法中执行。

    $this->_redirectReferer(); 
    

    将在不在模型中的控制器上工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-11-03
      • 1970-01-01
      • 2012-07-12
      • 2013-10-16
      • 1970-01-01
      • 2018-01-18
      • 2013-10-12
      相关资源
      最近更新 更多