2014-09-19 56 views
0

我創建了一個croncommand和函數中使用SQL語句,但是當我通過命令php protected/yiic cron運行它,它會拋出錯誤:警予createcommand不工作的cron

exception 'CException' with message 'CConsoleApplication and its behaviors do not have a method or closure named "createCommand".' in /home/sbl13/public_html/atp/yii/framework/base/CComponent.php:266

我的功能是

public function actionSendFeedbackReminder() 
{ 
    $sql = "SELECT training.id,session.trainingid, 
    group_concat(session.id),min(c_startdate) AS start, 
    max(c_enddate) AS end,training.programid,catalog.title 
    FROM training JOIN session ON 
    session.trainingid=training.id 
    JOIN catalog ON catalog.id=training.catalogueid 
    WHERE training.active=1 and session.active=1 
    GROUP BY trainingid"; // query to get data from databse 
    $data = Yii::app()->createCommand($sql)->queryAll(); //throws error here 
} 

我沒有從谷歌

回答

1

createCommand得到任何幫助的CDbConnection的功能,而不是CConsoleApplication。您的代碼應爲:

$data = Yii::app()->db->createCommand($sql)->queryAll();