How to enable downloading csv in dashboard report just like email list signups add-on
Permalink
Hi,
I want to add a download to csv button in the report dashboard.
And I wrote the following block of code in a single page in the single_pages/dashboard/report folder:
And in the corresponding controller file, I wrote following action method:
But when I click on the download button in the dashboard, I will be redirected to the page whose url ended with "/download_surveys/", and I was told "Page Not Found", and no file was downloaded.
Thanks
Spencer
I want to add a download to csv button in the report dashboard.
And I wrote the following block of code in a single page in the single_pages/dashboard/report folder:
And in the corresponding controller file, I wrote following action method:
public function download_surveys() { header('Content-type: text/csv'); header('Content-Disposition: attachment; filename="comic_viewer_survey.csv"'); $surveys = $this->getSurveys(); echo "Comic Issue Name,IP,Rating Score,Age Group,Comment,Email,Created,Confirmed\n"; foreach($surveys as $survey) { echo "{$survey->comicIssueName},"; echo "{$survey->ip},"; echo "{$survey->surveyRating},"; echo "{$survey->surveyAge},"; echo "{$survey->surveyEmail},"; echo "{$survey->surveyComment},"; echo "{$survey->created},"; echo "{$survey->confirmed}\n"; }
Viewing 15 lines of 17 lines. View entire code block.
But when I click on the download button in the dashboard, I will be redirected to the page whose url ended with "/download_surveys/", and I was told "Page Not Found", and no file was downloaded.
Thanks
Spencer
Did you install the single_page via the dashboard? You need to do that in addition to having the files there. Also, double-check that the controller class name is correct (this is the cause of a lot of errors).
Hi jordanlev,
I install the single_page via a package, the same as you did in the email list signup add-on. The strange thing is that when I try to use the code in the corresponding files for the dashboard report in your email list signup add-on, it works. But when I change the name of the action method in both places I mentioned above. The problem will occur. But the name of the method does not conflict anything, I think.
Maybe this is a bug in Concrete5?
Thanks
I install the single_page via a package, the same as you did in the email list signup add-on. The strange thing is that when I try to use the code in the corresponding files for the dashboard report in your email list signup add-on, it works. But when I change the name of the action method in both places I mentioned above. The problem will occur. But the name of the method does not conflict anything, I think.
Maybe this is a bug in Concrete5?
Thanks
Kind of hard to diagnose just based on your post... can you ZIP up the entire package and post that?
Hi jordanlev,
I have attached the zip file of the package I created. Now the action method in the dashboard report, I use the same name as yours. But if I change it to another name, when I click the download button, I would be redirected to a page whose url ended with the action method name and I was told the page did not exist.
Thank you very much.
I have attached the zip file of the package I created. Now the action method in the dashboard report, I use the same name as yours. But if I change it to another name, when I click the download button, I would be redirected to a page whose url ended with the action method name and I was told the page did not exist.
Thank you very much.
I tried this out (Concrete5.5.2.1) and it worked just fine. You might need to clear your site cache (type "Clear Cache" into the Intelligent Search box to get to that page in the dashboard).
Otherwise, make sure you are in fact changing it to "download_surveys" in BOTH the single_page form action AND the controller method.
Otherwise, make sure you are in fact changing it to "download_surveys" in BOTH the single_page form action AND the controller method.
Hi jordanlev,
Thank you very much! After I cleared the cache, the problem did not exist any more.
Thank you very much! After I cleared the cache, the problem did not exist any more.