views:

46

answers:

3

I have a site of about 60 tabular report pages. Want to convert this to Zend. The report has two states: empty report and filled in with data report. Each report has its own set of input boxes and select drop downs to narrow down searches. You click on submit and it retrieves the data. Thats all each page does.

Do I create 60 controllers with each one with default index action and getData action? All I have read online do not really describe how to architect a real site.

+1  A: 

If the method of fetching and retrieving data is pretty similar as you mention between all 60 reports. It would seem silly 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 store your report name, and you can abstract and delegate the logic off to some 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 then 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!

engfer
A: 

this is an old question: have you found an answer?

I've built a modular reporting system similar to the one proposed by engfer

Reports go in a subdirectory tree off the Models directory, all derived from a base class that has template methods to

  • return a Zend_DB_Select for the main query
  • fetch a filter form for display (to narrow down searches)
  • store the filter values in the session (so that page 2, page 3 etc will still show the right data)
  • pass the filter values into the select
  • handle pagination
  • format output for HMTL, and for CSV export

The main controller then loads one of these classes and handles calling the template methods. Happy to email it or upload somewhere: its too big to copy / paste here (half a dozen files)

Steve
A: 

Why do it in Zend? Do it in CodeIgniter = better results in half the time.

Jaffa