Is there a way to put a select box on every row of the items on grid list view for example to delete selected records.
I already tried setting a public variable on my model like $_select and on my CGridView settings
...
'columns'=>array(
array(
'header'=>'',
'name'=>'_select',
'value'=>CHtml::checkBox('selectedItems', false, array('value'=>$model->id)),
),
...
Another issue. I know I’m doing something wrong. -like always!
I’ve created this files and I want ajax delete selected itens but I don’t get it working!!! What am I doing wrong?
controllers/GalleriesController.php
...
public function actionView()
{
$model=$this->loadModel();
$dataProvider=new CActiveDataProvider('GalleriesImages', array(
'criteria'=>array(
'condition'=>'galleryId=' . $model->id,
),
'pagination'=>array(
'pageSize'=>30,
),
));
$this->render('view',array(
'model'=>$model,
'dataProvider'=>$dataProvider,
));
}
...
views/galleries/view.php
...
<div class="form">
<?php echo CHtml::beginForm(); ?>
<?php $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_viewImages',
'template'=>"{pager}\n{sorter}\n{items}\n{summary}\n{pager}",
'sortableAttributes'=>array(
'caption',
'description',
'dateCreation',
),
)); ?>
<div class="row buttons">
<?php echo CHtml::ajaxSubmitButton('Delete Selected', CHtml::normalizeUrl(array('galleriesimages/delete'))); ?>
</div>
<?php echo CHtml::endForm(); ?>
...
views/galleries/_viewImages.php
...
<?php
$model=$this->loadModel();
$directoryUrl=CC::getMediaPath(true) . $model->title . '/';
?>
<?php echo CHtml::checkBox('selectedImages', false, array('value'=>$data->id) ); ?>
<a rel="gallery" href="<?php echo $directoryUrl . CHtml::encode($data->filename); ?>" target="_blank">
<img src="<?php echo $directoryUrl . CHtml::encode($data->filenameThumbnail);?>" alt="<?php echo CHtml::encode($data->caption);?> " />
</a>
...
controllers/GalleriesImagesController.php
...
public function actionDelete()
{
if(Yii::app()->request->isPostRequest)
{
if(!Yii::app()->request->isAjaxRequest)
{
$this->loadModel()->delete();
} else {
foreach($_POST['selectedImages'] as $i)
{
$model=GalleriesImages::model()->findbyPk($i);
$model->delete();
Yii::app()->end();
}
}
if(!isset($_GET['ajax']))
$this->redirect($_SERVER['HTTP_REFERER']);
} else {
throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
}
}
...
Thanks for help!