[left]Hi! I’m newbie in Yii. I’m having a problem with a search function with limit.
The model function:
[i]/**
-
Retrieves a list of models based on the current search/filter conditions.
-
@return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
*/
public function search($number)
{
$criteria=new CDbCriteria;
$criteria->limit = $number;
$criteria->offset = 0;
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}[/i]
The controller function calling to search
[i]public function actionReadItems($number = 200)
{
$links = new Links;
$l = $links->search($number)->getData();
…
}[/i]
In table links, there are 10 items, the $number parameter is 2, but I get 10 items as a result instead of 2. What I’m doing wrong?
When I print what is in $criteria:
[i]CDbCriteria#1
(
[select] => '*'
[distinct] => false
[condition] => ''
[params] => array()
[limit] => '2'
[offset] => 0
[order] => ''
[group] => ''
[join] => ''
[having] => ''
[with] => null
[alias] => null
[together] => null
[index] => null
[scopes] => null
[CComponent:_e] => null
[CComponent:_m] => null
)
[/i]