我有一个大约60个表格报告页面的网站。我想把它转换成Zend。报表有两种状态:空报表和已填写数据报表。每个报告都有自己的一组输入框,并选择下拉列表来缩小搜索范围。单击submit,它将检索数据。这就是每个页面所做的一切。
我要创建60个控制器,每个控制器都有默认索引操作和getData操作吗?我在网上读到的所有内容都没有真正描述如何构建一个真正的网站。
发布于 2010-05-26 22:22:17
如果获取和检索数据的方法非常类似于您在所有60个报告中提到的方法。创建60个控制器(+PHP文件)似乎很愚蠢。
您可以向路由器添加一个路由,该路由将自动存储您的报告名称,并且您可以将逻辑抽象并委托给某个report -runner-business-object之类的东西。
$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'))
);然后在你的控制器里有类似这样的东西。
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();
}你明白了;希望这对你有所帮助!
https://stackoverflow.com/questions/2894648
复制相似问题