Zend Framework 如何从我的 Application_Model_Report 访问不同的表类?
我有一个报告模型,我将其用作获取各种报告数据的所有函数的主容器。该报告模型具有以下功能
protected $_dbTable;
public function setDbTable($dbTable)
{
if (is_string($dbTable))
{
$dbTable = new $dbTable();
}
if (!$dbTable instanceof Zend_Db_Table_Abstract)
{
throw new Exception('Invalid table data gateway provided');
}
$this->_dbTable = $dbTable;
return $this;
}
public function getDbTable($dbTable)
{
if (null === $this->_dbTable)
{
$this->setDbTable($dbTable);
}
return $this->_dbTable;
}
public function agentDailyCollections()
{
//$db =
$sql = $this->getDbTable('Application_Model_DbTable_Groupsloandetails'`enter code here`)->select()
->setIntegrityCheck(false)
->from(array('gl' => 'groups_loan_details'), array())
->join(array('ml' => 'members_loan_details'), 'gl.id = ml.groups_loan_details_id',
array('SUM(ml.daily_payment) AS GroupDailyPayment'))
->join(array('m' => 'members'), 'ml.members_id = m.id', array('id AS ID', 'first_name AS MFirstName', 'surname AS MSurname'))
->join(array('g' => 'groups'), 'gl.groups_id = g.id', array('group_name'))
->join(array('u' => 'users'), 'gl.loan_officer = u.id', array('id AS OID', 'first_name', 'surname'))
->where('gl.loan_end >=?', date(Y.'-'.m.'-'.d))
->where('gl.occur = ?', 'Active')
->group('(u.id)')
->group('(g.group_name)')
->group('(m.id) WITH ROLLUP');
return $this->getDbTable()->fetchAll($sql);
}
public function groupsWithMembers()
{
$sql = $this->getDbTable('Application_Model_DbTable_Members')->select()
->setIntegrityCheck(false)
->from(array('m' => 'members'), array())
->join(array('g' => 'groups'), 'm.groups_id = g.id')
->group('(g.group_area_residence)')
->group('(g.group_name) WITH ROLLUP');
return $this->getDbTable()->fetchAll($sql);
}
在我尝试根据不同的报告要求访问不同的表时,我将所需表类的名称传递给 getDbTable 函数,期望它为我获取表的对象。它有点工作,但后来我收到以下错误消息
Warning: Missing argument 1 for Application_Model_Report::getDbTable(), called in D:\www\gepm\application\models\Report.php on line 131 and defined in D:\www\gepm\application\models\Report.php on line 22`enter code here`
,我知道我正在做的事情有根本性的错误,但不确定是什么。需要帮助,那些只是想了解这个对象/zend 框架的事情。谢谢。
I have a report model which I am using as the main container for all the functions that fetch various report data. This report model has the following functions
protected $_dbTable;
public function setDbTable($dbTable)
{
if (is_string($dbTable))
{
$dbTable = new $dbTable();
}
if (!$dbTable instanceof Zend_Db_Table_Abstract)
{
throw new Exception('Invalid table data gateway provided');
}
$this->_dbTable = $dbTable;
return $this;
}
public function getDbTable($dbTable)
{
if (null === $this->_dbTable)
{
$this->setDbTable($dbTable);
}
return $this->_dbTable;
}
public function agentDailyCollections()
{
//$db =
$sql = $this->getDbTable('Application_Model_DbTable_Groupsloandetails'`enter code here`)->select()
->setIntegrityCheck(false)
->from(array('gl' => 'groups_loan_details'), array())
->join(array('ml' => 'members_loan_details'), 'gl.id = ml.groups_loan_details_id',
array('SUM(ml.daily_payment) AS GroupDailyPayment'))
->join(array('m' => 'members'), 'ml.members_id = m.id', array('id AS ID', 'first_name AS MFirstName', 'surname AS MSurname'))
->join(array('g' => 'groups'), 'gl.groups_id = g.id', array('group_name'))
->join(array('u' => 'users'), 'gl.loan_officer = u.id', array('id AS OID', 'first_name', 'surname'))
->where('gl.loan_end >=?', date(Y.'-'.m.'-'.d))
->where('gl.occur = ?', 'Active')
->group('(u.id)')
->group('(g.group_name)')
->group('(m.id) WITH ROLLUP');
return $this->getDbTable()->fetchAll($sql);
}
public function groupsWithMembers()
{
$sql = $this->getDbTable('Application_Model_DbTable_Members')->select()
->setIntegrityCheck(false)
->from(array('m' => 'members'), array())
->join(array('g' => 'groups'), 'm.groups_id = g.id')
->group('(g.group_area_residence)')
->group('(g.group_name) WITH ROLLUP');
return $this->getDbTable()->fetchAll($sql);
}
In my attempt to have access to different tables as per the different report requirement, I pass the name of the needed table class to the getDbTable function expecting it to get an object of the table for me. It kinda works but then I get the following error message
Warning: Missing argument 1 for Application_Model_Report::getDbTable(), called in D:\www\gepm\application\models\Report.php on line 131 and defined in D:\www\gepm\application\models\Report.php on line 22`enter code here`
I know there is something fundamentally wrong with what I am doing but not sure what. Need help guys just trying to get head round this object/zend framework thing. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您错过了函数参数的默认值,请尝试更改
:
I think you missed default value for argument on your function, try to change:
with