Yii2:检查基于数据库的复选框表

时间:2016-10-18 17:45:04

标签: php mysql yii2

我在我的数据库中有这样的关系: My Relation

现在,我的数据库中有这样的记录,

表格请求

   mysql> select ID_REQUEST, NOMOR_SURAT, KELUHAN, DITERIMA_OLEH FROM request;
    +------------+-------------+---------+---------------+
    | ID_REQUEST | NOMOR_SURAT | KELUHAN | DITERIMA_OLEH |
    +------------+-------------+---------+---------------+
    |          1 |           1 | a       | Dzil          |
    |          2 |           2 | A       | Pealariannya  |
    +------------+-------------+---------+---------------+
    2 rows in set (0.00 sec)

table tipe_request

   mysql> SELECT * FROM tipe_request;
        +---------+------------+
        | ID_TIPE | NAMA_TIPE  |
        +---------+------------+
        |       1 | Perbaikan  |
        |       2 | Permintaan |
        +---------+------------+
     2 rows in set (0.00 sec)
    mysql>

表link_req_type

 mysql> select * from link_req_tipe;
+---------+------------+---------+
| ID_LINK | ID_REQUEST | ID_TIPE |
+---------+------------+---------+
|       1 |          1 |       1 |
|       2 |          1 |       2 |
|       3 |          2 |       2 |
+---------+------------+---------+
3 rows in set (0.00 sec)
mysql>

问题是,我有一个表格旨在更新表link_req_type

public function actionUpdate($id) {

    $model = $this->findModel($id);
    $tipeRequest = new LinkReqTipe();


    if ($model->load(Yii::$app->request->post()) && $model->save()) {
        return $this->redirect(['view', 'id' => $model->ID_REQUEST]);
    } else {
        return $this->render('update', [
                    'model' => $model,
                    'tipeRequest' => $tipeRequest::find()->where(['ID_REQUEST' => $id])->all(),
        ]);
    }
}

我把它们插入清单。这是更新的观点:

<?php

    use yii\helpers\Html;

    /* @var $this yii\web\View */
    /* @var $model app\models\Request */

    $this->title = 'Update Request: ' . $model->ID_REQUEST;
    $this->params['breadcrumbs'][] = ['label' => 'Requests', 'url' => ['index']];
    $this->params['breadcrumbs'][] = ['label' => $model->ID_REQUEST, 'url' => ['view', 'id' => $model->ID_REQUEST]];
    $this->params['breadcrumbs'][] = 'Update';
    ?>
    <div class="request-update">

        <?=
        $this->render('_form', [
            'model' => $model,
            'tipeRequest' => $tipeRequest
        ])
        ?>

</div>

如果表中存在该值,如何检查核对清单?

比方说,ID_REQUEST = 2,然后是/index.php?r=it%2Frequest%2Fupdate&id=1 然后,将检查所有复选框。

Coz,我的代码现在在 _form.php

中是这样的
 <div class="col-md-6">
     <?=
      $form->field($tipeRequest, 'ID_TIPE')->inline(true)->checkBoxList(
         ArrayHelper::map(TipeRequest::find()->all(), 'ID_TIPE', 'NAMA_TIPE')
      )
     ?>
 </div>

0 个答案:

没有答案