hi gyz, I created a search interface… which comes with pagination… So I did a model, view and then its controller as usual… The view has a Datte range… from first_date to second_date . So the results are returned using a CGridView widget in a grid…and paginates so well The problem is when I click on next pages say page 2…3.4 no data is loaded… I have put the sources below here:
/// View
<?php
?>
<br><br>
<h3> Cancel Bills . </h3>
<br>
<div class="form">
<?php $form=$this->beginWidget(‘CActiveForm’, array(
'id'=>'bill-search-form',
'enableAjaxValidation'=>false,
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary(array($model)); ?>
<table>
<tr>
<td>
<?php echo $form->labelEx($model,‘first_date’); ?><br>
<?php
$this->widget(‘zii.widgets.jui.CJuiDatePicker’, array(
'model'=>$model,
‘attribute’=>‘first_date’,
‘value’=>(isset(Yii::app()->request->cookies[‘first_date’])) ? Yii::app()->request->cookies[‘first_date’]->value : ‘’,
// additional javascript options for the date picker plugin
‘options’=>array(
'showAnim'=>'fold',
‘dateFormat’=>‘yy-mm-dd’,
),
‘htmlOptions’=>array(
// ‘style’=>‘height:40px;’,
),
));
?>
<br><?php echo $form->error($model,‘first_date’); ?>
</td>
<td>
<?php echo $form->labelEx($model,‘second_date’); ?><br>
<?php
$this->widget(‘zii.widgets.jui.CJuiDatePicker’, array(
'model'=>$model,
‘attribute’=>‘second_date’,
‘value’=>(isset(Yii::app()->request->cookies[‘second_date’])) ? Yii::app()->request->cookies[‘second_date’]->value : ‘’,
// additional javascript options for the date picker plugin
‘options’=>array(
'showAnim'=>'fold',
‘dateFormat’=>‘yy-mm-dd’,
),
‘htmlOptions’=>array(
// ‘style’=>‘height:40px;’,
),
));
?>
<br><?php echo $form->error($model,‘second_date’); ?>
</td>
</tr>
<tr>
<td>
<?php echo $form->labelEx($model,‘cust_contnum’); ?><br>
<?php echo $form->textField($model,‘cust_contnum’,array(‘value’=>(isset(Yii::app()->request->cookies[‘cust_contnum’])) ? Yii::app()->request->cookies[‘cust_contnum’]->value : ‘’,)); ?>
<br><?php echo $form->error($model,‘cust_contnum’); ?>
</td>
<td>
<div class="row buttons">
<?php echo CHtml::submitButton('Submit To Search'); ?>
</div>
</td>
</tr></table>
<?php $this->endWidget(); ?>
</div>
/// Model
<?php
class Cancelpay extends CActiveRecord
{
public $first_date;
public $second_date;
public $cust_contnum;
public static function model($className=__CLASS__)
{
return parent::model($className);
}
public function tableName()
{
return 'cancelpay';
}
public function primaryKey(){
return 'BillID';
}
public function rules()
{
return array(
array('first_date, second_date', 'required'),
array('cust_contnum', 'safe'),
array('first_date,second_date', 'date', 'format'=>'yyyy-MM-dd'),
array('cust_contnum', 'numerical', 'integerOnly'=>true),
array('first_date,second_date', 'compare', 'compareValue'=>date('Y-m-d').'23:59:59', 'operator'=>'<','message'=>'No Date should be greater than today'),
array('first_date', 'compare', 'compareAttribute'=>'second_date', 'operator'=>'<=','message'=>'First Date Cannot be Greater than Second Date'),
array('cust_contnum', 'authAccountnum','allowEmpty'=>true),
array('TotalBill', 'numerical'),
array('BillingDate', 'safe'),
array('BillID, FirstName, ContractNo, BillingDate, TotalBill,first_date, second_date,cust_contnum', 'safe', 'on'=>'search'),
);
}
public function relations()
{
return array(
);
}
public function authAccountnum($attribute,$params)
{
$record=Custdetails::model()->findByAttributes(array('ContractNo'=>$this->cust_contnum));
if(!empty($this->cust_contnum)){
if($record===null){
$this->addError($attribute, 'Account Number for the Customer You Entered does not exist');
} }
}
public function attributeLabels()
{
return array(
'BillID' => 'Bill ID',
'FirstName' => 'Customer Name',
'ContractNo' => 'Account No',
'BillingDate' => 'Billing Date',
'TotalBill' => 'Amount Billed',
);
}
public function search()
{
$criteria=new CDbCriteria;
$criteria->condition = "BillingDate >= '$this->first_date' AND BillingDate <= '$this->second_date'";
$criteria->compare('ContractNo',$this->cust_contnum,true );
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
'pagination' => false,
));
}
}
/// Controllers Action
public function actionIndex()
{
unset(Yii::app()->request->cookies['first_date']); // first unset cookie for dates
unset(Yii::app()->request->cookies['second_date']);
unset(Yii::app()->request->cookies['cust_contnum']);
// $model=new Testing;
$model=new Cancelpay('search');
$model->unsetAttributes(); // clear any default values
if(isset($_POST['Cancelpay']))
{
$model->attributes=$_POST['Cancelpay'];
if($model->validate())
{
$model->attributes=$_POST['Cancelpay'];
Yii::app()->request->cookies['first_date'] = new CHttpCookie('first_date', $model->first_date); // define cookie for first_date
Yii::app()->request->cookies['second_date'] = new CHttpCookie('second_date', $model->second_date);
Yii::app()->request->cookies['cust_contnum'] = new CHttpCookie('cust_contnum', $model->cust_contnum);
/* $this->ffirst_date = $model->first_date;
$this->ssecond_date = $model->second_date.' 23:59:59';
$this->ccust_contnum = $model->cust_contnum; */
$this->render('admin',array(
'model'=>$model,
));
Yii::app()->end();
}
else { $this->render('index',array('model'=>$model)); Yii::app()->end();}
}
$this->render('index',array('model'=>$model));
}
Any help I will appreciate, thankyou