Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.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
Yii,从Javascript函数调用控制器函数_Javascript_Php_Yii - Fatal编程技术网

Yii,从Javascript函数调用控制器函数

Yii,从Javascript函数调用控制器函数,javascript,php,yii,Javascript,Php,Yii,我有一个html按钮,我想通过控制器动作生成报告,例如 在my PaymentController.php中 public function actionGenerateRI($date){...} 在我的admin.php中 <button type="button" onclick="generateRI()">Generate</button> <script> function generateRI(){ var date = docume

我有一个html按钮,我想通过控制器动作生成报告,例如

在my PaymentController.php中

public function actionGenerateRI($date){...}
在我的admin.php中

<button type="button" onclick="generateRI()">Generate</button>

<script>
function generateRI(){
    var date = document.getElementById("month").value +"-"+ document.getElementById("year").value;
    //what should I write here to call the actionGenerateRI? 
}
</script>
生成
函数生成器(){
变量日期=document.getElementById(“月”).value+“-”+document.getElementById(“年”).value;
//我应该在这里写什么来调用ActionGeneratori?
}
如何使用按钮调用控制器函数并传递变量
日期

p/S:它们都在同一个型号中,在本例中,
Payment

你可以试试这个

var date = document.getElementById("month").value +"-"+ document.getElementById("year").value;

// If you are using path format
window.location.href= '<?php echo Yii::app()->createUrl('payment/generateRI'); ?>' + '/date/'+encodeURI(date);

// otherwise
window.location.href= '<?php echo Yii::app()->createUrl('payment/generateRI'); ?>' + '&date='+encodeURI(date);

// For more variables
window.location.href= '<?php echo Yii::app()->createUrl('payment/generateRI'); ?>' + '&date='+encodeURI(date)+'&variable2='+var2_value+'&variable3='+var3_value+'...;
var date=document.getElementById(“月”).value+“-”+document.getElementById(“年”).value;
//如果您使用的是路径格式
window.location.href='+'/date/'+encodeURI(日期);
//否则
window.location.href='+'和date='+encodeURI(日期);
//获取更多变量
window.location.href='+'&date='+encodeURI(date)+'&variable2='+var2_value+'&variable3='+var3_value+'。。。;

如果我想传递2个或更多变量,我可以知道应该怎么做吗?