我是 Yii 框架的新手。我必须在我的表单(update.php)中创建三个按钮。即(保存、批准、拒绝)。我在我的表单中使用以下字段。
<?php
/* @var $this MessageTemplateController */
/* @var $model MessageTemplate */
/* @var $form CActiveForm */
?>
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'message-template-form',
'enableAjaxValidation'=>false,
)); ?>
<?php
echo $form->errorSummary($model);
?>
<div class="row">
<?php //$model->ReviewedDate=date('Y-m-d H:i:s');?>
<?php echo $form->labelEx($model,'ReviewedDate'); ?>
<?php echo $form->textField($model,'ReviewedDate',array('value'=>'0000-00-00 00:00:00','readonly' => true)); ?>
<?php echo $form->error($model,'ReviewedDate'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'SmsText'); ?>
<?php echo $form->textArea($model,'SmsText',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($model,'SmsText'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'UpdatedDate'); ?>
<?php echo $form->textField($model,'UpdatedDate'); ?>
<?php echo $form->error($model,'UpdatedDate',array('value'=>date('Y-m-d H:i:s'),'readonly' => true)); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'Approved'); ?>
<?php echo $form->hiddenField($model, 'Approved'); ?>
<?php echo $form->error($model,'Approved'); ?>
</div>
<div class="row">
<div class="row">
<?php echo $form->labelEx($model_al, 'username'); ?>
<?php $identity=Yii::app()->user->name;?>
<?php echo $form->textField($model_al, 'username',array('value'=>$identity,'readonly' => true), array('size' => 60, 'maxlength' => 250)); ?>
<?php echo $form->error($model_al, 'username'); ?>
<div>
<div class="row">
<?php echo $form->labelEx($model_al, 'updatedtime'); ?>
<?php echo $form->textField($model_al, 'updatedtime',array('value'=>date('Y-m-d H:i:s'),'readonly' => true), array('size' => 60, 'maxlength' => 250)); ?>
<?php echo $form->error($model_al, 'updatedtime'); ?>
<div>
<div class="row">
<?php echo $form->labelEx($model_al, 'comments on approval/rejection'); ?>
<?php echo $form->textField($model_al, 'comments',array('size' => 60, 'maxlength' => 250)); ?>
<?php echo $form->error($model_al, 'comments'); ?>
<div>
<div class="row buttons">
<?php echo CHtml::submitButton('Save', array('name' => 'save')); ?>
<? echo ' '; ?>
<?php echo CHtml::submitButton('Accept', array('name' => 'accept')); ?>
<? echo ' '; ?>
<?php echo CHtml::submitButton('Reject', array('name' => 'reject')); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
approved
现在我已经创建了三个按钮。上面的表单中有一个字段。当我单击以下按钮时,我希望此操作发生:
1. Save - All fields have to be saved but not approved(keep it as default).
2. Accept - All fields have to be saved with Approved changing to 1 in database.
3.Reject - All fields have to be saved with Approved changing to 0 in database.
我怎样才能做到这一点。
编辑 我在我的控制器中添加了以下内容。
public function actionUpdate($id)
{
$model_mt=new Messagesintable;
$model_al=new AuditLogin;
$model=$this->loadModel($id);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['MessageTemplate']) && isset($_POST['AuditLogin']))
{
$model->attributes=$_POST['MessageTemplate'];
list($name,$mobile,$email)=retrieve_persondetails($id);
if($model->save())
{
$model_al->attributes=$_POST['AuditLogin'];
if ($model_al->save())
$this->redirect(array('admin','id'=>$model->Id));
}
}
$this->render('update',array(
'model'=>$model,
));
}