symfony - Export .csv from database with symfony2 -
i didn't method work, maybe has idea.
/** * @route("/export", name="export") * @template("appbundle:expenses:export.html.twig") */ public function exportaction() { $repository = $this->getdoctrine()->getrepository('appbundle:expenses'); $query = $repository->createquerybuilder('s'); $query->orderby('s.id', 'desc'); $data = $query->getquery()->getresult(); $filename = "export_".date("y_m_d_his").".csv"; $response = $this->render('appbundle:expenses:export.html.twig', array('data' => $data)); $response->setstatuscode(200); $response->headers->set('content-type', 'text/csv'); $response->headers->set('content-description', 'submissions export'); $response->headers->set('content-disposition', 'attachment; filename='.$filename); $response->headers->set('content-transfer-encoding', 'binary'); $response->headers->set('pragma', 'no-cache'); $response->headers->set('expires', '0'); return $response; }
i got:
unable find expenses entity. 404 not found - notfoundhttpexception
the funny thing: in other method working:
$entity = $em->getrepository('appbundle:expenses')->find($id);
so, there expenses entity under appbundle. error come from?
-- routes:
[router] current routes name method scheme host path _assetic_bootstrap_css /styles/bootstrap.css _assetic_bootstrap_css_0 /styles/bootstrap__bootstrap_1.css _assetic_bootstrap_css_1 /styles/bootstrap_form_2.css _assetic_bootstrap_js /javascripts/bootstrap.js _assetic_bootstrap_js_0 /javascripts/bootstrap_transition_1.js _assetic_bootstrap_js_1 /javascripts/bootstrap_alert_2.js _assetic_bootstrap_js_2 /javascripts/bootstrap_button_3.js _assetic_bootstrap_js_3 /javascripts/bootstrap_carousel_4.js _assetic_bootstrap_js_4 /javascripts/bootstrap_collapse_5.js _assetic_bootstrap_js_5 /javascripts/bootstrap_dropdown_6.js _assetic_bootstrap_js_6 /javascripts/bootstrap_modal_7.js _assetic_bootstrap_js_7 /javascripts/bootstrap_tooltip_8.js _assetic_bootstrap_js_8 /javascripts/bootstrap_popover_9.js _assetic_bootstrap_js_9 /javascripts/bootstrap_scrollspy_10.js _assetic_bootstrap_js_10 /javascripts/bootstrap_tab_11.js _assetic_bootstrap_js_11 /javascripts/bootstrap_affix_12.js _assetic_bootstrap_js_12 /javascripts/bootstrap_bc-bootstrap-collection_13.js _assetic_jquery /javascripts/jquery.js _assetic_jquery_0 /javascripts/jquery_jquery-1.11.1_1.js _assetic_fddb9b6 /css/fddb9b6.css _assetic_fddb9b6_0 /css/fddb9b6_part_1.css _assetic_ae00be7 /styles/all.css _assetic_ae00be7_0 /styles/all_part_1_main_1.css _assetic_215113c /js/215113c.js _assetic_215113c_0 /js/215113c_part_1.js _assetic_cd44034 /js/cd44034.js _assetic_cd44034_0 /js/cd44034_part_1.js _wdt /_wdt/{token} _profiler_home /_profiler/ _profiler_search /_profiler/search _profiler_search_bar /_profiler/search_bar _profiler_purge /_profiler/purge _profiler_info /_profiler/info/{about} _profiler_phpinfo /_profiler/phpinfo _profiler_search_results /_profiler/{token}/search/results _profiler /_profiler/{token} _profiler_router /_profiler/{token}/router _profiler_exception /_profiler/{token}/exception _profiler_exception_css /_profiler/{token}/exception.css _configurator_home /_configurator/ _configurator_step /_configurator/step/{index} _configurator_final /_configurator/final _twig_error_test /_error/{code}.{_format} dashboard / seite2 /seite2 seite3 /seite3 expenses /expenses/ expenses_create post /expenses/ expenses_new /expenses/new expenses_show /expenses/{id} expenses_edit /expenses/{id}/edit expenses_update put /expenses/{id} expenses_delete delete /expenses/{id} expenses_export /expenses/export userlogin /login userlogincheck /login_check userlogout /logout userregister /register user /user/ user_new /user/new user_show /user/{id} user_edit /user/{id}/edit user_update put /user/{id} user_delete delete /user/{id} login /login login_check /login_check
Comments
Post a Comment