我没有让这种方法起作用,也许有人有想法。
/**
* @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;
}
我得到了:
Unable to find Expenses entity.
404 Not Found - NotFoundHttpException
有趣的事情: 在另一种方法中,这是有效的:
$entity = $em->getRepository('AppBundle:Expenses')->find($id);
所以,AppBundle下确实有一个费用实体。错误来自哪里?
- 我的路线:
[router] Current routes
Name Method Scheme Host Path
_assetic_bootstrap_css ANY ANY ANY /styles/bootstrap.css
_assetic_bootstrap_css_0 ANY ANY ANY /styles/bootstrap__bootstrap_1.css
_assetic_bootstrap_css_1 ANY ANY ANY /styles/bootstrap_form_2.css
_assetic_bootstrap_js ANY ANY ANY /javascripts/bootstrap.js
_assetic_bootstrap_js_0 ANY ANY ANY /javascripts/bootstrap_transition_1.js
_assetic_bootstrap_js_1 ANY ANY ANY /javascripts/bootstrap_alert_2.js
_assetic_bootstrap_js_2 ANY ANY ANY /javascripts/bootstrap_button_3.js
_assetic_bootstrap_js_3 ANY ANY ANY /javascripts/bootstrap_carousel_4.js
_assetic_bootstrap_js_4 ANY ANY ANY /javascripts/bootstrap_collapse_5.js
_assetic_bootstrap_js_5 ANY ANY ANY /javascripts/bootstrap_dropdown_6.js
_assetic_bootstrap_js_6 ANY ANY ANY /javascripts/bootstrap_modal_7.js
_assetic_bootstrap_js_7 ANY ANY ANY /javascripts/bootstrap_tooltip_8.js
_assetic_bootstrap_js_8 ANY ANY ANY /javascripts/bootstrap_popover_9.js
_assetic_bootstrap_js_9 ANY ANY ANY /javascripts/bootstrap_scrollspy_10.js
_assetic_bootstrap_js_10 ANY ANY ANY /javascripts/bootstrap_tab_11.js
_assetic_bootstrap_js_11 ANY ANY ANY /javascripts/bootstrap_affix_12.js
_assetic_bootstrap_js_12 ANY ANY ANY /javascripts/bootstrap_bc-bootstrap-collection_13.js
_assetic_jquery ANY ANY ANY /javascripts/jquery.js
_assetic_jquery_0 ANY ANY ANY /javascripts/jquery_jquery-1.11.1_1.js
_assetic_fddb9b6 ANY ANY ANY /css/fddb9b6.css
_assetic_fddb9b6_0 ANY ANY ANY /css/fddb9b6_part_1.css
_assetic_ae00be7 ANY ANY ANY /styles/all.css
_assetic_ae00be7_0 ANY ANY ANY /styles/all_part_1_main_1.css
_assetic_215113c ANY ANY ANY /js/215113c.js
_assetic_215113c_0 ANY ANY ANY /js/215113c_part_1.js
_assetic_cd44034 ANY ANY ANY /js/cd44034.js
_assetic_cd44034_0 ANY ANY ANY /js/cd44034_part_1.js
_wdt ANY ANY ANY /_wdt/{token}
_profiler_home ANY ANY ANY /_profiler/
_profiler_search ANY ANY ANY /_profiler/search
_profiler_search_bar ANY ANY ANY /_profiler/search_bar
_profiler_purge ANY ANY ANY /_profiler/purge
_profiler_info ANY ANY ANY /_profiler/info/{about}
_profiler_phpinfo ANY ANY ANY /_profiler/phpinfo
_profiler_search_results ANY ANY ANY /_profiler/{token}/search/results
_profiler ANY ANY ANY /_profiler/{token}
_profiler_router ANY ANY ANY /_profiler/{token}/router
_profiler_exception ANY ANY ANY /_profiler/{token}/exception
_profiler_exception_css ANY ANY ANY /_profiler/{token}/exception.css
_configurator_home ANY ANY ANY /_configurator/
_configurator_step ANY ANY ANY /_configurator/step/{index}
_configurator_final ANY ANY ANY /_configurator/final
_twig_error_test ANY ANY ANY /_error/{code}.{_format}
dashboard ANY ANY ANY /
seite2 ANY ANY ANY /seite2
seite3 ANY ANY ANY /seite3
expenses GET ANY ANY /expenses/
expenses_create POST ANY ANY /expenses/
expenses_new GET ANY ANY /expenses/new
expenses_show GET ANY ANY /expenses/{id}
expenses_edit GET ANY ANY /expenses/{id}/edit
expenses_update PUT ANY ANY /expenses/{id}
expenses_delete DELETE ANY ANY /expenses/{id}
expenses_export GET ANY ANY /expenses/export
userLogin ANY ANY ANY /login
userLoginCheck ANY ANY ANY /login_check
userLogout ANY ANY ANY /logout
userRegister ANY ANY ANY /register
user GET ANY ANY /user/
user_new ANY ANY ANY /user/new
user_show GET ANY ANY /user/{id}
user_edit GET ANY ANY /user/{id}/edit
user_update PUT ANY ANY /user/{id}
user_delete DELETE ANY ANY /user/{id}
login ANY ANY ANY /login
login_check ANY ANY ANY /login_check