2010-09-09 45 views
2

我在模型上有一個靜態方法'findAll',它基本上獲取具有特定條件的所有行。此方法工作正常,我可以使用它:靜態方法,Zend_View錯誤

$m::findAll(); 

其中$ m是模型名稱作爲變量。我可以輸出這個,它會返回正確的結果。然而,當分配這在Zend_View的對象的變量,如:

$this->view->viewvariable = $m::findAll(); 

我得到的錯誤:

Zend_Db_Table_Exception: Too many columns for the primary key

任何想法,爲什麼?

找到所有功能:

final public static function findAll($where = false, array $options = array()) { 
    $object = new static(); 

    if (!empty($options)) $options = array_merge($object->options, $options); 
    else $options = $object->options; 

    $run = $object->buildDefaultSelect($where, $options); 
    $rows = $run->fetchAll(); 
    if ($options['asObject'] == true) { 
    $result = array(); 
    foreach ($rows as $r) { 
    $class = new static(); 
    $class->setInfo($r); 
    $result[] = $class; 
    } 
    return $result; 
    } else { 
    if (count($rows) > 0) return $rows; 
    else return array(); 
    } 
} 

注:此功能工作正常無處不在除了分配到一個視圖變量時。如果我運行下面的代碼(不將其分配給視圖變量),它將顯示正確的數組數據。

var_dump($m::findAll($module['where'], $module['options'])); 
    exit; 

在我看來(我已經取代實際名稱與viewvariable這個職位的緣故):

<?php foreach($this->viewvariable as $item) { ?> 
//Do some echoing of data in $item 
//Close foreach 
+0

此模型是否具有複合PK?你是否在分配時遇到這個錯誤,或者當你嘗試迭代模板中的RS時? – prodigitalson 2010-09-09 20:55:42

+0

有助於查看'findAll()'後面的代碼的一小部分。' – 2010-09-09 21:16:03

+0

@proditalson在作業中。 – Ashley 2010-09-09 21:25:08

回答

1

我懷疑問題是與Zend_View。沒有看到您的代碼很難說,但我的猜測是findAll()正在使用Zend_Table_Dbfind()函數不正確。

據我所知,唯一引起異常的地方Zend_Db_Table_Abstract上的find()功能。

也許,findAll()函數內(或在一個函數調用)你正在做的其中之一:

$zendDbTable->find(1,2) //is looking for a compound key 
$zendDbTable->find(array(1,2)) //is looking for two rows 

當你真正想要的正好相反。

+0

我沒有在我的代碼中的任何地方使用find函數....查看函數 – Ashley 2010-09-09 21:26:11

+0

的更新後的帖子但可能有人調用它,可能是'$ run-> fetchAll()' 。 'Zend_View'不會拋出'Zend_Db_Table_Exception'。我的猜測是你不能運行沒有任何參數的'$ m :: findAll()'(你的示例工作代碼添加了參數)。 – 2010-09-09 21:58:28

+0

感謝您的更新,但它會產生一個解析錯誤。運行findAll沒有變數是可以的。 – Ashley 2010-09-09 22:01:21