Kindly help me in the following code. I am trying to fetch data by filling it an array and then sending it to CListView using ArrayDataProvier. But I dont know how to handle the view:
ControllerFunction:
public function actionIndex()
{
$connection=Yii::app()->db;
$user = Yii::app()->user->getId();
$rows= $connection->createCommand()->select('*')->from('tbl_project_user_assignment')
->where(‘user_id=:id’,array(’:id’=>Yii::app()->user->getId()))->queryAll();
//$rows=$command->execute();
foreach($rows as $row){
//process each item here
$pid=$row['project_id'];
//echo $pid;
$rows2= Yii::app()->db->createCommand()->select('*')->from('tbl_project')
->where(‘id=:pid’,array(’:pid’=>$pid))->queryAll();
//$rows2=$command2->execute();
$arr=array();
$i=0;
foreach($rows2 as $row) {
$arr=array(
$i=>array(
'id'=>$row['id'],
'name'=>$row['name'],
'description'=>$row['description'],
'create_time'=>$row['create_time'],
'create_user_id'=>$row['create_user_id'],
'update_time'=>$row['update_time'],
'update_user_id'=>$row['update_user_id']
),
);
$i++;
}
}
$dataProvider=new CArrayDataProvider([
'allModels' => $arr,
'pagination' => [
'pageSize' => 10,
],
'sort' => [
'attributes' => ['id', 'name'],
],
]);
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}
index.php file:
<?php
$this->widget(‘zii.widgets.CListView’, array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
));
?>
_view file:
<?php
/* @var $this ProjectController */
/* @var $data Project */
?>
<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('name')); ?>:</b>
<?php echo CHtml::encode($data->name); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('description')); ?>:</b>
<?php echo CHtml::encode($data->description); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('create_time')); ?>:</b>
<?php echo CHtml::encode($data->create_time); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('create_user_id')); ?>:</b>
<?php echo CHtml::encode($data->create_user_id); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('update_time')); ?>:</b>
<?php echo CHtml::encode($data->update_time); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('update_user_id')); ?>:</b>
<?php echo CHtml::encode($data->update_user_id); ?>
<br />
</div>