开发者

Zend Framework how do i access different table classes from my Application_Model_Report?

开发者 https://www.devze.com 2023-01-25 21:05 出处:网络
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

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_DbTabl开发者_如何转开发e_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.


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

public function getDbTable($dbTable)
{

with

public function getDbTable($dbTable = null)
{
0

精彩评论

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

关注公众号