我怎样才能在zend框架中调用模型

时间:2011-12-25 12:51:44

标签: php zend-framework zend-db-table

Here is my code

现在在第75到104行中使用交易连接,我创建了一个像这样的单独模型交易

<?php

class Application_Model_DbTable_Transactions extends Zend_Db_Table_Abstract
    {


           public function transactions {

                            $db = Zend_Db_Table::getDefaultAdapter();      
                            $sSqlT1 = "Insert into transactions (txnId, txnDateTime, partnerId, pointsProgramId, points, extTxnId) VALUES (uuid(), now(), '$partnerId', '$pointsProgramId',$pointsNeeded, '$voucherid')";
                            $create_voucher_txn_stmt = $this->db->query($sSqlT1);
                            error_log(__FUNCTION__.' : line '.__LINE__.' : ' .$sSqlT1);

                            try{ // If transactions successfully added...
                                    $sSqlT2 = "select max(txnId) as txnId from transactions where extTxnId='$voucherid'";
                                    $select_Txn_stmt = $this->db->query($sSqlT2);
                                    $txnid_get_results = $select_Txn_stmt->fetchall();
                                    $txnId = $txnid_get_results['0']['txnId'];
                            }
                            catch(Exception $e){
                                    error_log('Exception in '.__FUNCTION__.' : line '.__LINE__.' : '.$e->getMessage());
                            }
                            return $txnId;

    }

我在此模型中缺少此'$partnerId', '$pointsProgramId',$pointsNeeded, '$voucherid'此参数如何在此处调用

并且在创建此模型后,我再次想要在75到104之间调用它

我正在尝试这个

$transa=new Application_Model_DbTable_Transactions;
$tResult = $trans->transactions();

1 个答案:

答案 0 :(得分:0)

尝试

<?php

class Application_Model_DbTable_Transactions extends Zend_Db_Table_Abstract
{
    public function transactions( $partnerId, $pointsProgramId, $pointsNeeded, $voucherid )
    {
        $db     = Zend_Db_Table::getDefaultAdapter();
        $sSqlT1 = "Insert into transactions (txnId, txnDateTime, partnerId, pointsProgramId, points, extTxnId) VALUES (uuid(), now(), '{$partnerId}', '{$pointsProgramId}', {$pointsNeeded}, '{$voucherid}')";

        $create_voucher_txn_stmt = $this->db->query($sSqlT1);

        error_log(__FUNCTION__.' : line '.__LINE__.' : ' .$sSqlT1); 

        try
        {
            $sSqlT2            = "select max(txnId) as txnId from transactions where extTxnId='{$voucherid}'";
            $select_Txn_stmt   = $this->db->query( $sSqlT2 );
            $txnid_get_results = $select_Txn_stmt->fetchall();
            $txnId             = $txnid_get_results['0']['txnId'];
        }
        catch ( Exception $e )
        {
            error_log('Exception in '.__FUNCTION__.' : line '.__LINE__.' : '.$e->getMessage() ); 
        }

        return $txnId;
    }
}