2016-03-08 155 views
1

這是我的CActiveDataProvider查詢。Yii 1:CActiveDataProvider不返回所有記錄

$startDate='2016-02-28'; 
$endDate='2016-03-05'; 
    $criteria= new CDbCriteria(); 
     $criteria->with=array('job','job.serviceType'); 
     $criteria->order='t.uploaded_date DESC'; 
     $criteria->select='t.id,t.job_master_id,t.image_path,t.image_name,t.uploaded_date'; 
    $criteria->condition="SUBSTRING_INDEX(t.`image_name`,'.',-1) in ('jpg','jpeg','png','gif','JPG','PNG','GIF','JPEG') and job.trade_company_id='".Yii::app()->user->getState('TradeCompanyId')."' and job.current_assigned='".Yii::app()->user->id."'"; 
$criteria->addBetweenCondition('DATE(uploaded_date)', $endDate, $startDate); 

這給了我0行。但是當我在mysql中使用相同的查詢時,它給了我適當的結果。以下是相同的MySQL查詢

SELECT `t`.`job_master_id` 
FROM `media` `t` 
LEFT OUTER JOIN `job_master` `job` ON (`t`.`job_master_id` = `job`.`id`) 
INNER JOIN `service_type_master` `serviceType` ON (`job`.`service_type_id` = `serviceType`.`id`) 
WHERE (
    (
     SUBSTRING_INDEX(t.`image_name` , '.' , -1) IN ('jpg', 'jpeg', 'png', 'gif', 'JPG', 'PNG', 'GIF', 'JPEG') 
     AND job.trade_company_id = '7' AND job.current_assigned = "14" 
    ) 
    AND (
     DATE(uploaded_date) BETWEEN '2016-02-28' AND '2016-03-05' 
    ) 
) 
ORDER BY `t`.`uploaded_date` DESC 

我試着在CActiveDataProvider設置分頁至1000,但是這沒有什麼工作。

$dataProvider= new CActiveDataProvider($model,array('criteria'=>$criteria,'pagination' =>array('pageSize'=>1000))); 

即使我設置分頁到false但還是沒有結果

$dataProvider= new CActiveDataProvider($model,array('criteria'=>$criteria,'pagination' =>false)); 

回答

0

你有Parse error到您的$criteria->conditionjob.current_assigned="'.Yii::app()->user->id.'""

嘗試用此字符串來替換它:

$criteria->condition="SUBSTRING_INDEX(t.`image_name`,'.',-1) in ('jpg','jpeg','png','gif','JPG','PNG','GIF','JPEG') and job.trade_company_id='". 
    Yii::app()->user->getState('TradeCompanyId'). 
    "' and job.current_assigned='".Yii::app()->user->id."'"; 
+0

我解決了這個問題,但仍然沒有結果。它返回空白數組 – Dhara

+0

嘗試啓用日誌sql查詢並獲得由此$標準創建的真正查詢。例如。此答案可以幫助您在Yii中啓用查詢日誌記錄:http://stackoverflow.com/a/9898068/2253302 –