Hello folks,
I am trying to create a sortable list with "edit" and "delete" links by using CHTML::link.
Goal:
Create a sortable list with the ability to delete or update an entry in the list.
Issue:
The sorting it self is working and the results are stored to the DB. I am however trying to insert the links in the itemtemplate. I am unable to get the id for the chtml::link.
I used the knowledge described in this wiki entry as an example: Ordering Models by Weight with CJuiSortable
Controller
public function actionUpdate($id)
{
$model=$this->loadModel($id);
// Uncomment the following line if AJAX validation is needed
$this->performAjaxValidation($model);
if(isset($_POST['Catalog']))
{
$model->attributes=$_POST['Catalog'];
if($model->save())
$this->redirect(array('view','id'=>$model->id));
}
$dataProvider = new CActiveDataProvider('Catalogitem', array(
'pagination' => false,
'criteria' => array(
'condition' => 'catalog_id='.$id,
'order' => 'sort ASC, parameter DESC',
),
));
$this->render('update',array(
'model'=>$model,
'dataProvider'=>$dataProvider,
));
}
Relevant Viewpart
$items = CHtml::listData($dataProvider->getData(), 'id', 'parameter');
$delete = CHtml::link('Delete', '#', array('submit'=>array('catalogitem/delete', 'id'=>'{id}'), 'confirm'=>'Are you sure?'));
$this->widget('zii.widgets.jui.CJuiSortable', array(
'id'=>'orderlist',
'items' => $items,
'itemTemplate'=>'<li id="{id}" class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>{content}'.$delete.'</li>',
'options'=>array(
'placeholder'=>'ui-state-highlight',
),
));
Does anyone know how I can provide the $items id to the CHTML::link from the itemTemplate? If there is a better solution I am all ears