[英]How can I redirect to a another page after using request download cakephp2
I want to asking one question how to redirect to another page after using $this->response->download;
我想问一个问题如何在使用$this->response->download;
后重定向到另一个页面$this->response->download;
by cakephp 2 .I already use : by cakephp 2.我已经使用:
$this->response->download($new_file_name);
print($output);
$this->Flash->success(__('The file has been successfully export.'));
return $this->redirect(array('action' => 'index'));
but it not working well. 但它运作不佳。 Is it any another way ?Thanks 这是另一种方式吗?谢谢
This can't be done, it's a limitation in how browser requests work. 这是不可能的,它是浏览器请求工作方式的限制。 You can find more information in this answer . 您可以在此答案中找到更多信息。
The common thing (eg in popular download sites) is the reverse: first you go to the "after" page and then the download starts. 常见的事情(例如在流行的下载站点中)是相反的:首先,您转到“之后”页面然后开始下载。
So, redirect the user to where you want them to end up, and then serve the download. 因此,将用户重定向到您希望他们结束的位置,然后提供下载。
Try this,but not sure that will worked. 试试这个,但不确定是否会奏效。
$download='no';
$this->response->download($new_file_name);
print($output);
$download='yes';
if($download=='yes')
{
return $this->redirect(array('action' => 'index'));
}
else
echo 'sorry did not downloaded';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.