簡體   English   中英

Yii2:如何發送 model 和不屬於 model 的數組

[英]Yii2: How to send a model and an array that doesn't belong to the model

我需要將視圖中的表單發送到 controller 以及不屬於 model 的數組

我總是用這句話發送我的表格:

<?= Html::submitButton('Send') ?>

現在我還需要發送一個名為colors的數組。

您可以在表單中添加您需要的所有字段

<input type='text' class='form-control'  name = 'yourname[your_index]'  >

然后在 controller 中,您可以使用 $_POST 讀取內容

 $post = Yii::$app->request->post(); 

在 $post 中,您獲得與 model 相關的值,使用

    $model->load($post)

與 model 無關的值在

$post[yourname[your_index]] 

暫無
暫無

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

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