Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 基于Yii中的确认呈现操作_Php_Yii - Fatal编程技术网

Php 基于Yii中的确认呈现操作

Php 基于Yii中的确认呈现操作,php,yii,Php,Yii,我有个问题。是否有方法根据确认消息呈现其他操作? 例如,我有: <?php $this->widget('booster.widgets.TbButton', array( 'buttonType'=>'submit', 'context'=>'primary', 'htmlOptions' => array( 'id'=> '

我有个问题。是否有方法根据确认消息呈现其他操作? 例如,我有:

 <?php $this->widget('booster.widgets.TbButton', array(
        'buttonType'=>'submit',
        'context'=>'primary',
                        'htmlOptions'   => array(
                        'id'=> 'createstudent',
                        'confirm' => 'Do you want to register the student to a class'
                     ),
        'label'=>$model->isNewRecord ? Yii::t('default', 'Create') : Yii::t('default', 'Save'),
    )); ?>

我想做的是,当用户在确认对话框中单击“是”时,我想从另一个控制器呈现另一个动作。例如
合同/studentcreate,数组($model->studentid)
。如果用户单击“否”,则应渲染假定要渲染的操作。 提前谢谢你

是的,这是可能的。 您可以使用jQuery来完成它。您必须通过按钮捕获“单击”事件,当它发生时,您要求“确认”。如果用户在确认对话框中单击“是”,则对某些控制器/操作执行href;如果用户单击“否”,则对某些其他控制器/操作执行其他href。换言之:

<script>
   $("#createstudent").click(function() {
     if(confirm('Do you want to register the student to a class?')){
       location.href = "BASEURL/controllerOne/actionOne";
     }
     else{
       location.href = "BASEURL/controllerTwo/actionTwo";  
     }
  });
</script>

$(“#创建学生”)。单击(函数(){
如果(确认('您想将该学生注册到班级吗?')){
location.href=“BASEURL/controllerOne/actionOne”;
}
否则{
location.href=“BASEURL/controllerTwo/actionTwo”;
}
});
其中BASEURL是您开发项目所在web域中项目的基本url(如果您使用的是localhost,则为localhost),controllerOne是您在用户单击“是”时请求的控制器,actionOne是当用户单击“是”时调用的控制器“controllerOne”的操作。控制器二和动作二也一样

编辑: 您正在使用提交按钮。它有自己的href操作(表单的操作)。因此,您可能需要使用“a”链接创建自己的按钮。例如:

<a id="createstudent" style="margin-left: 8px; margin-top:-10px; padding: 5px; background-color: #EA7A00; color: white;  width: 62px; height: 25px; border: 1px solid #4B1800;cursor: pointer;">Example</a>
示例
一旦你点击它,它会根据你选择的选项(是或否)提示你采取正确的行动


当然,您必须根据自己的意愿编辑CSS样式。

Thanx的答案是Mundo。我想我已经解决了这个问题:

<script>
$("#createstudent").click(function(e){
    e.preventDefault();

bootbox.confirm("<?php echo Yii::t('default', 'Do you want to register this student?');?>", function(result) {
  if(result){
       $('#student-form').submit();
      window.location = 'http://localhost/myproject/index.php/contract/studentcreate/'+'<?php echo $maxid ?>';

  } else {
     console.log("Confirmed: "+result);
      $('#student-form').submit();
  }

 }); 
});
</script>

$(“#创建学生”)。单击(函数(e){
e、 预防默认值();
bootbox.confirm(“),函数(结果){
如果(结果){
$(“#学生表格”).submit();
window.location=http://localhost/myproject/index.php/contract/studentcreate/'+'';
}否则{
控制台日志(“已确认:+结果”);
$(“#学生表格”).submit();
}
}); 
});

我也会试试你的解决方案!再次感谢你的帮助

弹出消息会出现,但我单击什么并不重要。它调用默认操作。它会忽略location.href命令,可能是因为您使用的是提交按钮。它当然有自己的href操作(这将是表单的操作)。这意味着您需要创建自己的按钮作为“a”链接。例如,替换TbButton小部件:例如,一旦单击它,它将引导您执行正确的操作。当然,您必须根据自己的意愿编辑CSS样式。使用此解决方案时要小心。如果在有人单击“注册”按钮之前有多人加载页面,则可能会导致竞争情况。让您的
studentcreate
函数获得一个新的
$maxid
比让jquery在页面上已经有值要好。