paulwb
(Paul)
July 28, 2011, 1:03pm
1
I discovered that it is possible to create a "delete" link (or for other cases which is submitting a post request using Chtml:link.
CHtml::link('Delete', '#',
array('submit' => array('item/delete', 'id'=>$model->id), 'confirm' => 'Sure')
);
Is it possible to use this within a zii.widgets.CMenu as well? If yes, how?
This is what I use at the moment:
$this->widget('zii.widgets.CMenu',array(
'items'=>array(
array('label'=>'Löschen', 'url'=>array('/item/delete', 'id' => $model->id)),
)
);
Ekstazi
(Ekstazyst)
July 29, 2011, 9:17pm
2
I think linkOptions can help your.
paulwb
(Paul)
August 3, 2011, 10:07am
3
Thanks, that works.
$this->widget('zii.widgets.CMenu',array( 'items'=>array(
array('label'=>'Delete', 'url'=>'#',
'linkOptions'=>array(
'submit' => array('item/delete', 'id'=>$item->id), 'confirm' => 'Delete?'),
'visible'=>!Yii::app()->user->isGuest),
),
);
Thanks, this was very helpful for me as well. I’d like to point out a slight fix to your sample code, to give an example of correct parentheses/parameters passed to to linkOptions.
$this->widget('zii.widgets.CMenu', array(
'items'=>array(
array(
'label'=>'Delete',
'url'=>'#',
'linkOptions'=>array(
'submit' => array('item/delete', 'id'=>$item->id),
'confirm' => 'Delete?',
'visible'=>!Yii::app()->user->isGuest
),
),
),
));
Thanks, that works.
$this->widget('zii.widgets.CMenu',array( 'items'=>array(
array('label'=>'Delete', 'url'=>'#',
'linkOptions'=>array(
'submit' => array('item/delete', 'id'=>$item->id), 'confirm' => 'Delete?'),
'visible'=>!Yii::app()->user->isGuest),
),
);