在使用GridView时报出的错误是:
Invalid argument supplied for foreach()
错误位置是:
/** * Performs lazy find with the specified base record. * @param CActiveRecord $baseRecord the active record whose related object is to be fetched. */ public function lazyFind($baseRecord) { if(is_string($this->_table->primaryKey)) $this->records[$baseRecord->{$this->_table->primaryKey}]=$baseRecord; else { $pk=array(); foreach($this->_table->primaryKey as $name) $pk[$name]=$baseRecord->$name; $this->records[serialize($pk)]=$baseRecord; } foreach($this->stats as $stat) $stat->query(); if(!$this->children) return; $child=end($this->children); // bridge(s) inside, we're taking only last necessary child $query=new CJoinQuery($child);
Yii的连接查询结果为空,查询几遍都不行。
这个问题困扰我很长时间,我检查自己写的连接规则的问题,我反复检查几遍都没有找到问题所在,有一句:foreach($this->_table->primaryKey as $name)。最后想起前两天刚遇见一个更新问题因为没有设置主键出错。果然我把主键设置好以后问题就解决了。