Zend Framework 如何从我的 Application_Model_Report 访问不同的表类?

发布于 2024-10-03 01:21:37 字数 2583 浏览 8 评论 0原文

我有一个报告模型,我将其用作获取各种报告数据的所有函数的主容器。该报告模型具有以下功能

    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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墨洒年华 2024-10-10 01:21:37

我认为您错过了函数参数的默认值,请尝试更改

public function getDbTable($dbTable)
{

public function getDbTable($dbTable = null)
{

I think you missed default value for argument on your function, try to change:

public function getDbTable($dbTable)
{

with

public function getDbTable($dbTable = null)
{
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文