我有一個鏈接時,它通過渲染ajax從控制器請求一個頁面,以前我曾經只傳遞id,但現在我想傳遞一個額外的參數控制器,我如何做到這一點, 這是我曾嘗試傳遞yii2中的兩個參數ajax請求使用jQuery到控制器
這是鏈接」只有傳遞給控制器
Html::a('click me', ['#'],
['value' => Url::to('checktruck?id='.$model->id), //this is where the param is passed
'id' => 'perform']);
這是控制器代碼預計2個參數一個參數:
public function actionChecktruck($id,$category) //it expects 2 parameters from above link
{
$truckdetails = Truck::find()->where(['id' =>$id])->one();
if (Yii::$app->request->post()) {
$checklistperform = new TodoTruckChecklist();
$truck = Truck::find()->where(['id'=>$id])->one();
$checklistperform->truck_id=$id;
$checklistperform->registered_by=Yii::$app->user->identity->id;
$checklistperform->save();
$truck->update();
var_dump($checklistperform->getErrors());
//var_dump($truck->getErrors());
}
else {
$truckcategory = Checklist::find()->where(['truck_category'=>$truckdetails->truck_category])->andWhere(['checklist_category'=>$category])->all();
return $this->renderAjax('truckyard/_checklistform', [
'truckcategory' => $truckcategory,'truckvalue'=>$id,
]);
}
}
這是另一個按鈕後請求期間取決於上述控制器上的我的jQuery代碼
$("#postbutn").click(function(e) {
$.post("checktruck?id="+truckid, //here i would like to pass 2 params
{checked:checked,unchecked:unchecked,truckid:truckid}
)
}
這是jQuery代碼時,有沒有交
我如何可以傳遞一個額外的參數對於控制器