2015-02-07 56 views
1

在控制器我写以下无法查看findBySql导致

$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)); 

写我看到的结果列表。 该查询无误。

回答

1

您需要使用如下findAllBySql而不是findBySql:现在

$types=Types::model()->findAllBySql('SELECT t_id, t_name FROM ygs_types'); 

,你可以看到你想要的结果。

+0

谢谢,它帮助! – ETartaren 2015-02-07 17:12:10