小编Con*_*ugh的帖子

Yii2将表单字段数组保存到单个数据库字段中

如何在Yii2中保存字段数组,当前/默认设置仅适用于非数组的字段.

以下是我需要保存到单个字段中的表单字段:

<div class="repeat">
<table class="wrapper" width="100%">
    <thead>
        <tr>
            <td width="10%" colspan="4"><span class="add">Add</span></td>
        </tr>
    </thead>
    <tbody class="container">
    <tr class="template row">
        <td width="10%"><span class="move">Move</span></td>

        <td width="10%">An Input Field</td>

        <td width="70%">
            <?= $form->field($model, 'field1ofarray[{{row-count-placeholder}}]')->textInput(['maxlength' => 255])->label('Field Label') ?>
            <?= $form->field($model, 'fieldofarray[{{row-count-placeholder}}]')->textInput(['maxlength' => 255])->label('Som field') ?>
            <?= $form->field($model, 'field3ofarray[{{row-count-placeholder}}]')->textInput(['maxlength' => 255])->label('Field Label') ?>
            <?= $form->field($model, 'field4ofarray[{{row-count-placeholder}}]')->dropDownList(['instock' => 'Instock', 'soldout' => 'Sold Out', 'scheduled' => 'Scheduled']); ?>
        </td>

        <td width="10%"><span class="remove">Remove</span></td>
    </tr>
    </tbody>
</table>
Run Code Online (Sandbox Code Playgroud)

当前控制器(我需要知道如何循环数组并保存以及保存表单中的其他常规字段):

public function actionCreate()
{
    $model = new GrailWall();

    if …
Run Code Online (Sandbox Code Playgroud)

php arrays yii2

6
推荐指数
1
解决办法
1万
查看次数

Yii2根据模型要求设置数组形式字段

如果我具有以下表单字段(下面的代码),如何在模型中根据需要设置该字段,以便像其他字段一样,如果表单不包含信息,则无法提交该表单。

<?= $form->field($model, 'seo[seo_title]')->textInput(['maxlength' => 60])->label('SEO Title') ?>
Run Code Online (Sandbox Code Playgroud)

php validation model-view-controller yii2 yii2-advanced-app

5
推荐指数
1
解决办法
2868
查看次数