Yii,从Javascript函数调用控制器函数
我有一个html按钮,我想通过控制器动作生成报告,例如 在my PaymentController.php中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
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个或更多变量,我可以知道应该怎么做吗?