Hi, friends
please help me to find solution. In main layout of view, i created a link called Manage Order. when a user is clicked, CJuiDialog is opened and bind admin.php view (as CGridView) into that dialog. In that cgridview the user can view,edit and delte. In the same dialog when the user request to edit, i created an iframe and bind update.php view into that iframe. Once i clicked on edit, the update.php view was bind into that iframe, and then i closed the dialog. After that i open the dialog again and do the same action on edit, update.php view didn’t bind into that iframe without got any error message. that’s my problem. why?
sorry, if my bad English.
thanks so much.
layouts/main.php
<li>
<?php echo CHtml::ajaxLink('Manage Order',
$this->createUrl('/order/admin',array('inputField'=>'Manage_senderid')),
array('update'=>'#manage_order'),
array('id'=>'ManageOrderDialog'));
?>
</li>
controller/order.php
Action Admin
public function actionAdmin()
{
$model=new Order('search');
if( isset($_GET['inputField']) ){
$inputField=$_GET['inputField'];
}
$model->unsetAttributes(); // clear any default values
if(isset($_GET['Order']))
$model->attributes=$_GET['Order'];
$this->renderPartial('admin',array(
'model'=>$model,
'inputField'=>$inputField,
),false,true);
}
Action Update
public function actionUpdate($id)
{
$date=date('y-m-d');
$model=$this->loadModel($id);
$issave=false;
$product=new Products();
$orderdetail=OrderDetail::model()->findAll(array("condition"=>'order_id='.$_GET['id']));
if(isset($_POST['productorder'])){
$newOrderdetail=new OrderDetail();
$newOrderdetail->deleteAll(array("condition"=>'order_id='.$_GET['id']));
$p=$_POST['productorder'];
$q=$_POST['qtyorder'];
for($i=0; $i<count($p); $i++)
{
$mod = new OrderDetail;
$mod->product_id=$p[$i];
$mod->qty=$q[$i];
$mod->order_id= $model->order_id;
$mod->order_item_status=1;
$mod->created_date=$date;
$mod->updated_date=$date;
$mod->save();
$issave=true;
}
}
if($issave){
if (!empty($_GET['asDialog']))
{
//Close the dialog, reset the iframe and update the grid
echo CHtml::script("window.parent.$('#manageorderdialog').dialog('close');window.parent.$('#cru-frame').attr('src','');window.parent.$.fn.yiiGridView.update('{$_GET['gridId']}');");
Yii::app()->end();
}
else
//----- end new code --------------------
$this->redirect(array('view','id'=>$model->order_id,'sql'=>$this->sql));
}else{
Yii::log('Update fail','info','application.controllers.OrderController');
}
//----- begin new code --------------------
if (!empty($_GET['asDialog']))
$this->layout = '//layouts/iframe';
//----- end new code --------------------
$this->render('update',array(
'model'=>$model,
'orderdetail'=>$orderdetail,
'product'=>$product,
));
}
view/admin.php
<?php $this->beginWidget('zii.widgets.jui.CJuiDialog', array(
'id'=>'manageorderdialog',
// additional javascript options for the dialog plugin
'options'=>array(
'title'=>'Manage Order',
'autoOpen'=>true,
'modal'=>false,
'width'=>'auto',
'height'=>'auto',
))
);
?>
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'order-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'order_id',
'customer_id',
'order_status',
'lat',
'lng',
'address',
array(
'class'=>'CButtonColumn',
//--------------------- begin new code --------------------------
'buttons'=>array(
'update'=>
array(
'url'=>'$this->grid->controller->createUrl("update", array("id"=>$data->primaryKey,"asDialog"=>$data->primaryKey))',
'click'=>'function(){
alert("was click");
$("#cru-frame").attr("src",$(this).attr("href"));
$("#manageorderdialog").dialog("open"); return false;}',
),
'delete'=>array(
'url'=>'$this->grid->controller->createUrl("delete", array("id"=>$data->primaryKey,"asDialog"=>1,"gridId"=>$this->grid->id))',
//'click'=>'function(){$("#cru-frame").attr("src",$(this).attr("href")); $("#cru-dialog").dialog("open"); return false;}',
)
),
//--------------------- end new code --------------------------
),
),
)); ?>
<iframe id="cru-frame" class="frame_admin"></iframe>
<?php $this->endWidget('zii.widgets.jui.CJuiDialog');?>