我在模型上有一個靜態方法'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
此模型是否具有複合PK?你是否在分配時遇到這個錯誤,或者當你嘗試迭代模板中的RS時? – prodigitalson 2010-09-09 20:55:42
有助於查看'findAll()'後面的代碼的一小部分。' – 2010-09-09 21:16:03
@proditalson在作業中。 – Ashley 2010-09-09 21:25:08