Question

is there a way in Zend to call one controller from another?

I have seen the action stack but that does not seem to work for me and i have read that alot of people think it to be EVIL!

What i am trying to acchive is as follows:

Reports Controller scans through all the modules in the system, it then checks to see if a route has been registered for that module called MODULENAME-reports-run

The controller then reuns that registered route to generate all the reports from all the modules.

The idea is that i can create modules for my application that clients can simple drag and drop into place and the system picks up on the reports.

Was it helpful?

Solution

Your controller should not do any of these things. Your controller should only accept any input from the User Interface and then decide to delegate this to the appropriate classes in your Model.

If you have a ReportController, have it accept any input and forward it to a ReportsService or something else in the Model responsible for generating Reports. It's not the controllers responsibility to generate them.

It should look something like this:

public function generateReportAction()
{
    try {
        $service = new Model_ReportService;
        $service->setReportToGenerate($this->getRequest()->getParam('reportId'));
        $this->view->report = $service->generateReport();
    } catch (ReportException $e) {
        // do something with $e
    }
}

If your ReportService needs to generate multiple reports, change the ReportService so it knows how to do that. You could do something like

$service = new Model_ReportService;
$service->setModulesDirectory('something');
$this->view->reports = $service->generateReportsForModules();

Personally I dont think a ReportService should need to know about a Module Directory, so you will want to give the public interface of that Service some more thought. But in general, this is the way to go.

Whatever you do, dont do it in the controller. Controllers ought to be slim.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top