If the method of extracting and retrieving data is quite similar, as you indicate between all 60 reports. It would be foolish to create 60 controllers (+ PHP files).
It seems that you are trying to solve this problem with the default rewrite router. You can add a route to the router that will automatically save your report name, and you can abstract and delegate this logic to some element report-runner-business-object-thingy.
$router = $ctrl->getRouter(); // returns a rewrite router by default $router->addRoute( 'reports', new Zend_Controller_Router_Route('reports/:report_name/:action', array('controller' => 'reports', 'action' => 'view')) );
And something like this in your controller ...
public function viewAction() { $report = $this->getRequest()->getParam("report_name"); // ... check to see if report name is valid // ... stuff to set up for viewing report... } public function runAction() { $report = $this->getRequest()->getParam("report_name"); // ... check to see if report name is valid // Go ahead and pass the array of request params, as your report might need them $reportRunner = new CustomReportRunner( $report, $this->getRequest()->getParams() ); $reportRunner->run(); }
You get the point; hope this helps!
source share