Hi,
I want to make a pagination for my search, but it’s not work. This is my code :
public function actionList()
{
$criteria = new CDbCriteria;
$search = $_GET[search];
if($search!=""){
$pages=new CPagination(user::model()->getJumlah($search));
$pages->pageSize=1;
$pages->applyLimit($criteria);
$models=user::model()->searchId($search);
}
else{
$pages=new CPagination(user::model()->count($criteria));
$pages->pageSize=1;
$pages->applyLimit($criteria);
$models=user::model()->findAll($criteria);
}
$this->render('list',array(
'models'=>$models,
'pages'=>$pages,
));
}
If there is no search, it’s OK, paging works, but if I have a search, it shows all the records search result.
Please Help,
Thanks
funner
(Ujovlado)
2
because you haven’t any criteria.
you should add to your "else" statement:
...
else{
....
$criteria->addCondition("HERE WILL BE YOUR CRITERIA CONDITION");
....
}
...
if you want to find user with name “John” and $_GET[‘search’] == “John” (of course), then use:
$search = $_GET['search'];
$criteria->addCondition('user_name = '.$search);
and you should use:
if (isset($_GET['search'])) {
$search = $_GET['search'];
}
and read addCondition
Thanks for your reply, actually I just do not want to put something related to data in Controller,
I want to put all related to data in model, that is it.
I have another way tho do this, but I must put the condition in Controller
Is there any other way ?
Thanks