Zend框架模型构造失败,没有任何错误

时间:2013-04-30 16:50:59

标签: zend-framework frameworks model

我有一个Zend Framework应用程序在构建新模型时失败,但不会产生任何错误。这是实例化模型的代码:

    public function connectionAction()
    {
        $clientid= $this->session->client_id;
        try {
$this->_log->debug('partner connection');      
      $partnerModel = new Model_PartnerSettings();
$this->_log->debug('get partners');
      } catch(Exception $e) {
        $this->_log->debug('failed: '.print_r($e, 1));
      }      
      $partners = $partnerModel->getPartners($clientid);

      if(count($partners) == 0) {
        $partnerModel->addPartners($clientid);
        $partners = $partnerModel->getPartners($clientid);
      }

      $this->view->partners = $partners;
    }

这是Model类:    

class Model_PartnerSettings extends Zend_Db_Table_Abstract{

  protected $_name='partner_settings';

  public function getType($clientId, $partnerId)
  {
    $log = Zend_Registry::get('log');
    $db = Zend_Registry::get('db');

    $currRow = $this->getPartners($clientId, $partnerId);

    return $currRow['type'];
  }

  public function getName($clientId, $partnerId)
  {
    $log = Zend_Registry::get('log');
    $db = Zend_Registry::get('db');

    $currRow = $this->getPartners($clientId, $partnerId);

    return $currRow['name'];
  }

  public function getPartnerId($settingsId)
  {
    $where = $this->_db->quoteInto('rowid = ?', $settingsId);
    $row = $this->fetchRow($where);
    return $row['partnerinfoid'];
  }

  public function getActiveShipper($clientId)
  {
    $log = Zend_Registry::get('log');
    $db = Zend_Registry::get('db');

    $joinOn = 'partner_info.rowid = partner_settings.partnerinfoid';

    $select = $this->_db->select()
                        ->from($this->_name)
                        ->joinInner(
                            'partner_info',
                            $joinOn,
                            array('logo_file', 'status', 'type', 'name'))
                        ->where('partner_info.type = ?', 'shipping') 
                        ->where('clientid = ?', $clientId)
                        ->where('toggle_value = ?', 'on')
                        ->limit(1);
    return $currRow;
  }

  public function getPartners($clientId, $partnerId = null, $where = array())
  {
$this->_log->debug('getpartners');
    $log = Zend_Registry::get('log');
    $db = Zend_Registry::get('db');

    if(!$clientId || (count($where) > 0 && count($where) < 2)) {
      throw new Exception('Invalid Parameters');
    }

    if(!$partnerId) {
      $joinOn = 'partner_info.rowid = partner_settings.partnerinfoid';
    } else {
      $joinOn = $db->quoteInto('partner_info.rowid = ?', $partnerId);
    } 
    $select = $this->_db->select()
                        ->from($this->_name)
                        ->joinInner(
                            'partner_info',
                            $joinOn,
                            array('logo_file', 'status', 'type', 'name')) 
                        ->where('clientid = ?', $clientId);
    if(count($where)) { 
      $select->where($where[0] => $where[1]);
    }
$this->_log->debug('select='.print_r($select, 1));
    $result = ($partnerId) ? $db->fetchRow($select) : $db->fetchAll($select);
$this->_log->debug('res='.print_r($result, 1));
    return $result;
  } 

  public function addPartners($clientid)
  {
    $partnerInfoModel = new Model_PartnerInfo();

    $partners = $partnerInfoModel->fetchAll();

    foreach($partners as $partner) {
      $data = array(
        'partnerinfoid' => $partner['rowid'],
        'clientid' => $clientid,
        'toggle_value' => 'off'
      );
      $this->insert($data);
    }
  }

  public function toggleActivation($clientId, $partnerId)
  {
    $db = Zend_Registry::get('db');

    $where = array();
    $where[] = $db->quoteInto('clientid = ?', $clientId);
    $where[] = $db->quoteInto('partnerinfoid = ?', $partnerId);

    $currRow = $this->fetchRow($where);

    $toggleValue = ($currRow['toggle_value'] == 'on') ? 'off' : 'on';

    $this->update(array('toggle_value' => $toggleValue), $where);

    return $toggleValue;
  }

  public function getActiveShippingVendor($clientId, $partnerId)
  {
    return $this->getShipperName($clientId, $partnerId);
  }
}

在connectionAction()代码中,它永远不会比'$ partnerModel = new Model_PartnerSettings();'更远。线。我无法弄清楚出了什么问题。谢谢你的帮助。

0 个答案:

没有答案
相关问题