简体   繁体   中英

CakePHP refreshing page after successful file download

CakePHP 2.4: I have an index view with a list of projects. With a button on this page I can call an action 'exportxml' in 'ProjectsController.php' to download a file with information about the listed projects. After download has finished successfully I would need to change the state of all the projects. But I can not find a way how to do this.

After saving the file, the request is answered, the following commands are not executed anymore.

First I tried to render a view within a layout as usual in cakephp with appropriate header information set within the layout file. Then I tried with output buffering and setting header information within the controllers action. But with the same result. Everything after the ob_end_flush() is not executed anymore.

At least I would need to reload the index page to change the button, so the user could do the necessary actions manually after sucessfull download.

Is there any possibility to achieve this goal?

Thank you very much for any hint!

Probably it is not possible to answer one request with two different headers, to a file download and to the browser. I am not sure about that.

I found another solution. It is possible to render a view to a variable by adding no headers. I do that in a first step and then save the rendered page on the server to an xml file. If this is done without errors, I change the status of all selected records. After that I render the same view again but this time in another layout that adds the headers for the xml to download. Like this, the browser still is not updated, but at least I have some control, that every thing is done and done correctly.

Maybe this answer can help somebody who encounters similar problems.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM