dscojuxf69080 2016-10-18 17:45
浏览 26

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

I have relation in my database like this : My Relation

Now, I have a record in my database like this,

table request

   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>

table 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>

The problem is, I have a form that have aim to update the table 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(),
        ]);
    }
}

I interprated them into checklist. this is the view of update :

<?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>

How can I make the check list is checked if the value is exist in table ?

Let say, the ID_REQUEST = 2, then /index.php?r=it%2Frequest%2Fupdate&id=1 Then, the all checkbox will be checked.

Coz, my code now is like this in _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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图