i’m newbie yii, i use yii blog applicion
and i install extension updatedialog.
PostContonller
public function actionDelete()
{
$model = $this->loadModel();
if( Yii::app()->request->isAjaxRequest )
{
// Stop jQuery from re-initialization
Yii::app()->clientScript->scriptMap['jquery.js'] = false;
if( isset( $_POST['action'] ) && $_POST['action'] == 'confirmDelete' )
{
$model->delete();
echo CJSON::encode( array(
'status' => 'success',
'content' => 'Deleted succussfully',
));
exit;
}
else if( isset( $_POST['action'] ) )
{
echo CJSON::encode( array(
'status' => 'canceled',
'content' => 'Deletion canceled',
));
exit;
}
else
{
echo CJSON::encode( array(
'status' => 'failure',
'content' => $this->renderPartial( 'delete', array(
'model' => $model ), true, true ),
));
exit;
}
}
else
{
if( isset( $_POST['confirmDelete'] ) )
{
$model->delete();
$this->redirect( array( 'admin' ) );
}
else if( isset( $_POST['denyDelete'] ) )
$this->redirect( array( 'view', 'id' => $model->id ) );
else
$this->render( 'delete', array( 'model' => $model ) );
}
}
view post/admin.php
<?php
<?php $this->widget( 'ext.EUpdateDialog.EUpdateDialog' ); ?>
<?php
$this->breadcrumbs=array(
'Manage Posts',
);
?>
<h1>Manage Posts</h1>
<?php $this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
array(
'name'=>'title',
'type'=>'raw',
'value'=>'CHtml::link(CHtml::encode($data->title), $data->url)'
),
array(
'name'=>'status',
'value'=>'Lookup::item("PostStatus",$data->status)',
'filter'=>Lookup::items('PostStatus'),
),
array(
'name'=>'create_time',
'type'=>'datetime',
'filter'=>false,
),
array(
'class' => 'CButtonColumn',
'deleteButtonUrl' => 'Yii::app()->createUrl( "post/delete", array( "id" => $data->primaryKey ) )',
'buttons' => array(
'delete' => array(
'click' => 'updateDialogDelete',),
'update' => array(
'click' => 'updateDialogUpdate',),
),
),
),
)); ?>
view post/view.php
<?php $this->widget( 'ext.EUpdateDialog.EUpdateDialog', array(
'height' => 200,
'resizable' => true,
'width' => 300,
)); ?>
<?php
$this->breadcrumbs=array(
$model->title,
);
$this->pageTitle=$model->title;
?>
<?php $this->renderPartial('_view', array(
'data'=>$model,
)); ?>
<div id="comments">
<?php if($model->commentCount>=1): ?>
<h3>
<?php echo $model->commentCount>1 ? $model->commentCount . ' comments' : 'One comment'; ?>
</h3>
<?php $this->renderPartial('_comments',array(
'post'=>$model,
'comments'=>$model->comments,
)); ?>
<?php endif; ?>
<h3>Leave a Comment</h3>
<?php if(Yii::app()->user->hasFlash('commentSubmitted')): ?>
<div class="flash-success">
<?php echo Yii::app()->user->getFlash('commentSubmitted'); ?>
</div>
<?php else: ?>
<?php $this->renderPartial('/comment/_form',array(
'model'=>$comment,
)); ?>
<?php endif; ?>
</div><!-- comments -->
Plzzz i want code Update/delete model with CJuiDialog (works in CGridView).