Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何从控制器添加重定向_Php_Magento - Fatal编程技术网

Php 如何从控制器添加重定向

Php 如何从控制器添加重定向,php,magento,Php,Magento,我已经尝试了这里和那里找到的这个脚本的每个版本,但它仍然不起作用。 我让一个控制器在后端保存订单后执行某些操作。此操作之一是在特定条件下自动生成发票。通常重定向会将我返回到订单视图:我想改为转到发票视图 $url = Mage::helper('adminhtml')->getUrl('sales_order_invoice/view', array('invoice_id' => $invoice->getId(), 'order_id' => $order->g

我已经尝试了这里和那里找到的这个脚本的每个版本,但它仍然不起作用。 我让一个控制器在后端保存订单后执行某些操作。此操作之一是在特定条件下自动生成发票。通常重定向会将我返回到订单视图:我想改为转到发票视图

$url = Mage::helper('adminhtml')->getUrl('sales_order_invoice/view', array('invoice_id' => $invoice->getId(), 'order_id' => $order->getId()));
Mage::app()->getResponse()->setRedirect($url)->sendResponse();
此代码不起作用:我像往常一样被重定向到订单视图。观察者在
销售订单保存后触发。

如何正确重定向?

您可以使用下面的方法,它在管理员控制器的自定义模块中为我工作

$this->getResponse()->setRedirect(Mage::helper('adminhtml')->getUrl("adminhtml/sales_order/view", array('order_id'=>$order_num)));
        return;

希望这对你有用。如果我能为您提供更多帮助,请告诉我。

为什么不使用默认控制器重定向功能

function someAction()

{
  /* do your thing*/
     $this->_redirect('*/sales_invoice/view',
                       array('invoice_id'=> $invoice->getId())
     );
}
需要记住的一件事是_redirect(或您的方法)将重定向,直到操作函数完成。如果此重定向在“If语句”中,则需要添加一个返回;后缀以退出任何剩余功能。

Mage::app()->getResponse()->setRedirect(年龄::助手('adminhtml')->getUrl(“adminhtml/sales\u order/view”,数组('order\u id'=>$order\u num))->sendResponse();出口(0)
$this->getResponse()
null
<代码>退出(0)
成功了,谢谢阿米特·贝拉。无论如何,我发现我在实际创建发票之前调用了
$invoice->getId()
。。我现在必须弄清楚如何以及何时创建正确的url!