Hi friends,
How can I write an SQL query in criteria.
In my case, I want to create a function in model and then controller call model’s function to receive results in array format.
It is my code:
Model (I named "LichChay" is my model name)
public function getAvailableYearModel(){
$criteria = new CDbCriteria();
$criteria->select = "subStr(ngay_kh, 1,4) ngay";
$criteria->distinct = TRUE;
return LichChay::model()->findAll($criteria);
Controller:
public function getAvailableYear(){
return LichChay::model()->getAvailableYearModel();
}
View:
$years = $this->getAvailableYear();
I’d tested in phpmysql with statement:
SELECT DISTINCT substr( ngay_kh, 1, 4 ) years
FROM `lich_chay`
and it return my expect results. But with the above MVC, it seem no effective!
Any idea ?