2010-09-09 94 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