无法查看 findBySql 结果
Can not view findBySql results
在控制器中我写了以下内容
$types=Types::model()->findBySql('SELECT t_id, t_name FROM ygs_types');
$this->render('index', array('types'=>$types));
可见
$list = CHtml::listData($types, 't_id', 't_name');
foreach($list as $type) {
echo '<p>'.$type.'</p>';
}
但是我看不到任何结果。
如果我在控制器中写入
$typeModel = new Types();
$types = $typeModel->findAll();
$this->render('index', array('types'=>$types));
我看到了结果列表。
查询正确。
您需要使用 findAllBySql
而不是 findBySql
,如下所示:
$types=Types::model()->findAllBySql('SELECT t_id, t_name FROM ygs_types');
现在,您可以看到想要的结果了。
在控制器中我写了以下内容
$types=Types::model()->findBySql('SELECT t_id, t_name FROM ygs_types');
$this->render('index', array('types'=>$types));
可见
$list = CHtml::listData($types, 't_id', 't_name');
foreach($list as $type) {
echo '<p>'.$type.'</p>';
}
但是我看不到任何结果。
如果我在控制器中写入
$typeModel = new Types();
$types = $typeModel->findAll();
$this->render('index', array('types'=>$types));
我看到了结果列表。 查询正确。
您需要使用 findAllBySql
而不是 findBySql
,如下所示:
$types=Types::model()->findAllBySql('SELECT t_id, t_name FROM ygs_types');
现在,您可以看到想要的结果了。