Hi,
I am having a pagination problem with a CListview. I had the same problem when I tried before to do it with Cgridview. So I guess, my approach could be wrong.
I have a model Room. In its controller, I have an action which when called renders a form view where the user enters 3 data, one of which is an attribute of the model (roomtypeid) whereas the 2 others are not (these are month and year).
Following the submission of this form, I retrieve these 3 values in my controller action where I attribute one of these values to an attribute of the model and build a condition accordingly by means of CActiveDataProvider. I then need to render another view to the user where data displayed will be according to the condition which I specified.
My two problems are:
-
I have 34 result lines and the 1st page is displayed correctly. When I click on the link for the 2nd page, nothing is rendered. If I manually put insert the URL in my browser, I am redirected to the 1st form view where I need to input the 3 values. If I resubmit the form, then I get the 2nd page.
-
The other 2 values that are submitted in the form are parameters necessary for a function in the room model. The function takes as parameters the month and year and returns an information which varies according to the parameters. I have tested the function by hard coding it in one of my view files and it works fine. I am at a loss as to how to get the view to display this dynamic data.
Here are my codes:
[size="4"]RoomController:[/size]
public function actionOccup()
{
$model = new Room;
if(isset($_POST['Room']['roomtypeid']))
{
$mois= $_POST['mois']; $annee=$_POST['annee'];
$id = $_POST['Room']['roomtypeid'];
$dataProvider=new CActiveDataProvider('Room',array(
'criteria'=>array('condition'=>"roomtypeid='$id'")));
$this->render('crit',array(
'dataProvider'=>$dataProvider,
));
}
else
$this->render('occup',array(
'model'=>$model,
));
}
[size="4"]View file: occup.php[/size]
<?php
$this->breadcrumbs=array(
'Rooms'=>array('index'),
'Occupancy',
);
$this->menu=array(
array('label'=>'List Room', 'url'=>array('index')),
array('label'=>'Manage Room', 'url'=>array('admin')),
);
?>
<h1>Room Occupancy</h1>
<?php echo $this->renderPartial('_formline', array('model'=>$model)); ?>
[size="4"]View file: _formline.php[/size]
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'room-form',
'enableAjaxValidation'=>false,
)); ?>
<div class="row">
<?php echo $form->labelEx($model,'roomtypeid'); ?>
<?php echo $form->dropDownList($model,'roomtypeid',
CHtml::listData(Roomtype::model()->findAll(), 'id', 'id')); ?>
<?php echo $form->error($model,'roomtypeid'); ?>
Month
<SELECT name="mois" id ="mois">
<?php
for ($i=1; $i<=12; $i++){
echo "<option value='".$i."'>".date("F",mktime(0,0,0,$i,15,2012))."</option>";
}
?>
</SELECT>
Year
<SELECT name="annee" id ="annee">
<?php
$year = date("Y")-1;
for ($i=$year; $i<=$year+1; $i++){
echo "<option value='".$i."'>".$i."</option>";
}
?>
</SELECT>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton('Submit'); ?>
</div>
<?php $this->endWidget(); ?>
<div class="form">
[size="4"]View file: crit.php[/size]
<?php
$this->breadcrumbs=array(
'Rooms',
);
$this->menu=array(
array('label'=>'Create Room', 'url'=>array('create')),
array('label'=>'Manage Room', 'url'=>array('admin')),
array('label'=>'Room occupancy', 'url'=>array('occup')),
);
?>
<h1>Rooms</h1>
<?php $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_viewcrit',
)); ?>
[size="4"]View file: _viewcrit.php[/size]
<div class="view">
<b><?php echo CHtml::encode($data->getAttributeLabel('id')); ?>:</b>
<?php echo CHtml::link(CHtml::encode($data->id), array('view', 'id'=>$data->id)); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('roomtypeid')); ?>:</b>
<?php echo CHtml::encode($data->roomtypeid); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('description')); ?>:</b>
<?php echo CHtml::encode($data->description); ?>
<br />
<?php echo CHtml::encode($data->getline(7,2012)); ?>//hardcoded with the 2 values from the 1st form: month and year
Thanks beforehand for helping. I am at a loss!!
</div>