我在模型上有一个静态方法'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