开发者

Zend Framework Action Stack Alternative

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 thin开发者_Go百科k 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜