laravel - How to call several actions from within another action? -
i'm migrating non-mvc application laravel 4.2 , i'm unsure of best way accomplish task. have several reports created on routes this:
/reports/this_report /reports/that_report /reports/another_report
these actions query database, run bunch of calculations, , generate html tables , forms.
what need add page this:
/reports/dashboard
this dashboard page should display output of 3 reports in condensed format, each "click view details" link takes user main report page.
is there way dashboard action call each of report actions, , use output data in dashboard view?
here's little code of how this. i'm not sure how have structured, might have adapt little.
lets have route dashboard this.
route::get('/reports/dashboard', dashboardcontroller@showdashboard');
this route should call controller method processing.
class dashboardcontroller extends basecontroller { public function showdashboard() { return view::make('dashboard')->with(array( 'report1_data' => $this->getreport1data(), 'report2_data' => $this->getreport2data(), 'report3_data' => $this->getreport3data() )); } public function getreport1data() { //calculations, return array of results } public function getreport2data() { //calculations, return array of results } public function getreport3data() { //calculations, return array of results } public function showthisreport() { $data = $this->getreport1data(); return view::make('report')->with(array('data' => $data)); } public function showthatreport() { $data = $this->getreport2data(); return view::make('report')->with(array('data' => $data)); } public function showanotherreport() { $data = $this->getreport3data(); return view::make('report')->with(array('data' => $data)); } }
so, dashboard method call other methods (that include in controller) query database , calculate reports.
then returns view of data. view format data , display user.
now, make can see detailed view of each report, suggest adding couple more methods , routes show detailed views.
route::get('/reports/this_report', 'dashboardcontroller@showthisreport');
route::get('/reports/that_report', 'dashboardcontroller@showthatreport');
route::get('/reports/another_report', 'dashboardcontroller@showanotherreport');
i hope helps! luck.
Comments
Post a Comment