到目前为止,我已经完成了以下视图文件,我将数据发送到模型,tariffCardType,jobType,clothType,newRegularRate,newUrgentRate都是我必须作为数据发送的JavaScript变量
tariffcard.php(视图)
function saveRates(btnId, regularValue, urgentValue)
{
var clothType = btnId.substring(0, btnId.indexOf("-"));
var tariffCardType = btnId.substring(btnId.indexOf("-")+1, btnId.indexOf("-", btnId.indexOf("-")+1));
var jobTypeCode = btnId.substring(btnId.indexOf("-", btnId.indexOf("-")+1)+1, btnId.length);
var jobType = "iron";
<?php
echo CHtml::ajax(array(
'url'=> CController::createUrl("site/UpdateRates"),
'type'=>'get',
'data' => "{tarifftardtype:tariffCardType, jobtype:jobType, clothtype:clothType, newregularrate:newRegularRate, newurgentrate:newUrgentRate}",
'success'=> "function(html){document.getElementById('demo').innerHTML = html;}",
))
?>
}
我正在尝试访问模型中的数据,如下所示
TariffCardForm.php(模型)
public function updateTariffRates()
{
$response["tariffcardtype"] = Yii::$app->request->getPost('tarifftardtype');
$response["jobtype"] = Yii::$app->request->getPost('jobtype');
$response["clothtype"] = Yii::$app->request->getPost('clothtype');
$response["newregularrate"] = Yii::$app->request->getPost('newregularrate');
$response["newurgentrate"] = Yii::$app->request->getPost('newurgentrate');
return $response;
}
我使用的方法是访问模型中的数据是否正确?另外如何将javascript变量作为php数组中的数据发送?