Hello all
I am using CListView to show the data retrieved from a table. I want to generate a ajaxlink for every record. when i click on the ajaxlink it must post some data to an action in controller class and affects some part of page after success. but when i load the page the link doesn’t work.
my source code is as follows :
_view.php
<div class="view">
<b><?php echo CHtml::encode($data->getAttributeLabel('id')); ?>:</b>
<?php echo CHtml::ajaxLink(CHtml::encode($data->id),CController::createUrl('site/showSingleNews'),array(
'type'=>'POST',
'success'=>'js: function(data) {
$("#searchDialog").html(data);
$("#searchDialog").show();
}',
'data'=>array('id1'=>CHtml::encode($data->id)),
),array('id'=>CHtml::encode($data->id))); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('title')); ?>:</b>
<?php echo CHtml::encode($data->title); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('abstract')); ?>:</b>
<?php echo CHtml::encode($data->abstract); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('publishDate')); ?>:</b>
<?php echo CHtml::encode($data->publishDate); ?>
<br />
</div>
=====================================================================
searchPersonal.php
<?php $this->widget(‘zii.widgets.CListView’, array(
'dataProvider'=>$dataprovider,
'itemView'=>'_view',
)); ?>
=====================================================================
two actions in the controller :
public function actionSearch()
{
//$dataProvider=new CActiveDataProvider('News');
//$this->render('index',array(
// 'dataProvider'=>$dataProvider,
//));
$model=new News();
$dataProvider=$model->search1(Yii::app()->user->getId());
// renders the view file 'protected/views/site/index.php'
// using the default layout 'protected/views/layouts/main.php'
$this->renderPartial('_searchPersonalNews',array('dataprovider'=>$dataProvider));
}
public function actionShowSingleNews()
{
echo 'test';
}