2015-02-07 55 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