我在表中有一个名为Object的模型,其中包含一列object_type
。我想在表中显示object_type = journal
的所有记录,但是我收到错误“Undefined index:object_name”。我怎么称呼记录?
<tbody>
<?php
$type='journal';
$criteria = new CDbCriteria();
$criteria->condition = "object_type =:object_type";
$criteria->params = array(':object_type' => $type);
$results = Object::model()->findAll($criteria);
foreach ($results as $value);
{
echo '
<tr>
<td>'.$results['object_name'].'</td>
<td>'.$results['object_publisher'].'</td>
</tr>';
}
?>
以下工作代码
<?php
$type='journal';
$criteria = new CDbCriteria();
$criteria->condition = "object_type =:object_type";
$criteria->params = array(':object_type' => $type);
$results = Object::model()->findAll($criteria);
foreach ($results as $value)
{
echo '
<tr>
<td>'.$value->object_name.'</td>
<td>'.$value->object_publisher_name.'</td>
</tr>';
}
?>
答案 0 :(得分:1)
答案 1 :(得分:-1)
您希望$value
是数组,但它是对象。使用$results->object_name