我在TbGridView中使用了CButtonColumn。单击按钮我想要一个对话框,我想将邮件发送到recepient。 我的admin.php代码:
array(
'class'=>'CButtonColumn',
'template'=>'{dialog}',
'buttons'=>array(
'dialog' => array(
'label'=>'Email',
'imageUrl'=>Yii::app()->request->baseUrl.'/images/email_envelope.png',
'url'=>'Yii::app()->createUrl("todoList/OpenMailDialog", array("id"=>$data->to_do_id))',
'options'=>array(
'ajax'=>array(
'type'=>'POST',
'url'=>"js:$(this).attr('href')",
'update'=>'#dialog_id',
),
),
),
),
),
<div class="dialog_id" style="display:none;"></div>
我的控制器代码是:
public function actionOpenMailDialog($id){
$model=$this->loadModel($id);
$this->render('createDialog',array('model'=>$model,));
}
我的观看代码是:
<?php
$this->beginWidget('zii.widgets.jui.CJuiDialog',array(
'id'=>'mailDialog',
'options'=>array(
'title'=>'View Message #'. $model->id,
'autoOpen'=>true,
'modal'=>'true',
'width'=>'auto',
'height'=>'auto',
),
));
echo $this->renderPartial('_formDialog', array('model'=>$model)); ?>
<?php $this->endWidget('zii.widgets.jui.CJuiDialog');?>
我的_formDialog:
<div class="form" id="mailDialogForm">
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row col2">
<?php echo $form->labelEx($model,'email_from'); ?>
<?php echo $form->textField($model,'email_from',array('size'=>50,'maxlength'=>50,'readonly'=>'readonly')); ?>
<?php echo $form->error($model,'email_from'); ?>
</div>
<div class="row col2">
<?php echo $form->labelEx($model,'email_to'); ?>
<?php echo $form->textField($model,'email_to',array('size'=>60,'maxlength'=>150)); ?>
<?php echo $form->error($model,'email_to'); ?>
</div>
<div style="clear:both"></div>
<div class="row col2">
<?php echo $form->labelEx($model,'subject'); ?>
<?php echo $form->textField($model,'subject',array('size'=>60,'maxlength'=>250)); ?>
<?php echo $form->error($model,'subject'); ?>
</div>
<div style="clear:both"></div>
<div class="row">
<?php echo $form->labelEx($model,'message'); ?>
<?php echo $form->textArea($model,'message',array('rows'=>6, 'cols'=>50)); ?>
<?php echo $form->error($model,'message'); ?>
</div>
<div style="clear:both"></div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ?
'Send' :'Send',array('class' => 'btn')); ?>
</div>
我无法在此弹出对话框。解决方案是什么?
答案 0 :(得分:1)
我只是简单地查看了我的代码,现在正在运行。我的admin.php代码是这样的:
array(
'class'=>'CButtonColumn',
'template'=>'{dialog}',
'buttons'=>array(
'dialog' => array(
'label'=>'Email',
'imageUrl'=>Yii::app()->request->baseUrl.'/images/email_envelope.png',
'visible'=>'$data->user_id===Yii::app()->user->id?false:true',
'url'=>'Yii::app()->createUrl("todoList/openMailDialog", array("id"=>$data->to_do_id))',
),
),
),
我的_formDialog.php代码:
<div id="mailDialogForm">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'mail-form',
'enableAjaxValidation'=>true,
));
?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="rowcol">
<?php echo $form->labelEx($model,'email_from'); ?>
<?php echo $form->textField($model,'email_from',array('size'=>50,'maxlength'=>50,'readonly'=>'readonly')); ?>
<?php echo $form->error($model,'email_from'); ?>
</div>
<div class="rowcol">
<?php echo $form->labelEx($model,'email_to'); ?>
<?php echo $form->textField($model,'email_to',array('size'=>60,'maxlength'=>150,'readonly'=>'readonly')); ?>
<?php echo $form->error($model,'email_to'); ?>
</div>
<div style="clear:both"></div>
<div >
-----------------
</div>
<div class="rowbutton">
<?php echo CHtml::submitButton($model->isNewRecord ?
'Send' :'Send',array('class' => 'btn')); ?>
</div>
<?php $this->endWidget(); ?>
</div>