簡體   English   中英

Yii,從Javascript函數調用控制器函數

[英]Yii, calling controller function from Javascript function

我有一個html按鈕,我想通過控制器操作生成報告,例如,

在我的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>

如何使用我的按鈕調用控制器函數並傳遞可變date

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+'...;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM