Hi all,
Am a newbie to YII, I have a problem in pagination, it is when i fill the search keyword and click on submit, correct results are displayed in the first page i have set the pagesize to 25, So when i click on next page or page 2 in pagination it takes all the records from the DB but it should take the record depending on the search condition. Here's my coding
Form:
<script>
function displayactive()
{
window.location="<?php echo 'index.php?r=franchise_accounts/active' ?>";
}
function displayinactive()
{
window.location="<?php echo 'index.php?r=franchise_accounts/inactive' ?>";
}
function displayall()
{
window.location="<?php echo 'index.php?r=franchise_accounts/admin' ?>";
}
</script>
<form method="POST" action="index.php?r=franchise_accounts/details" name="dtl" >
<input type="radio" name="status" value="Active" checked="checked" onclick="displayactive();"> Active
<input type="radio" name="status" value="Inactive" onclick="displayinactive();"> Inactive
<input type="radio" name="status" value="All" onclick="displayall();"> All
<input style="float:right" class="greenbutton" type="submit" name="submit" value="Search" >
<input style="float:right" type="text" name="fran_loc" id="fran_loc" value="">
</form>
<?php $this->widget(‘zii.widgets.grid.CGridView’, array(
'id'=>'franchise-accounts-grid',
'dataProvider'=>$model->search_active(),
'summaryText'=>'',
//‘filter’=>$model,
'columns'=>array(
array('class'=>'CLinkColumn',
'label'=>'edit',
'imageUrl'=>'images/edit.png',
'urlExpression'=>'Yii::app()->createUrl("franchise_accounts/update", array("id"=>$data->franchise_account_id))',
),
'franchise_location_code:text:FRANCHISE LOCATION #',
'franchise_location_name:text:FRANCHISE LOCATION',
'first_name:text:FIRST NAME',
'last_name:text:LAST NAME',
'email_address_1:text:EMAIL',
'addwords_account_number:text:ADWORDS CLIENT ID',
),
));
?>
Controller:
public function actionDetails()
{
//if(isset($_POST['dtl']))
//{
//print_r($_POST);
//echo $stat;
//echo $id;
if($_POST['submit'])
{
$id = $_POST['fran_loc'];
$stat = $_POST['status'];
if($stat=='All')
{
//echo 'ALL';
$model_details=new franchise_accounts('search_details');
if(isset($_POST['dtl']))
$model_details->attributes=$_POST['dtl'];
$this->render('details',array(
'model'=>$model_details,
));
}
elseif($stat=='Active')
{
//echo 'Act';
$model_details=new franchise_accounts('search_details_active');
if(isset($_POST['dtl']))
$model_details->attributes=$_POST['dtl'];
$this->render('search_active',array(
'model'=>$model_details,
));
}
elseif($stat=='Inactive')
{
//echo 'Inac';
$model_details=new franchise_accounts('search_details_inactive');
if(isset($_POST['dtl']))
$model_details->attributes=$_GET['dtl'];
$this->render('search_inactive',array(
'model'=>$model_details,
));
}
else
{
// echo 'hii';
$this->render('details',array(
'model'=>$model_details,
));
}
}else
{
$model_details=new franchise_accounts('search_details');
$this->render('details',array(
'model'=>$model_details,
));
}
}
Model:
public function search_details()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
//$criteria->together = true;
$criteria->addSearchCondition('franchise_location_name','%'.$_POST['fran_loc'].'%',false);
//$criteria->compare('status');
return new CActiveDataProvider('franchise_accounts', array(
'criteria'=>$criteria,
'pagination'=>array(
'pageSize'=>25,
),
));
}
public function search_details_active()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
//$criteria->together = true;
$criteria->addSearchCondition('franchise_location_name','%'.$_POST['fran_loc'].'%',false);
$criteria->compare('status',1);
return new CActiveDataProvider('franchise_accounts', array(
'criteria'=>$criteria,
'pagination'=>array(
'pageSize'=>25,
),
));
}
public function search_details_inactive()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
//$criteria->together = true;
$criteria->addSearchCondition('franchise_location_name','%'.$_POST['fran_loc'].'%',false);
$criteria->compare('status',0);
return new CActiveDataProvider('franchise_accounts', array(
'criteria'=>$criteria,
'pagination'=>array(
'pageSize'=>25,
),
));
}
I don’t know what am missing or doing mistake…Please help me!!!