Yii Framework Forum: Get data value with checkboxlist - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Get data value with checkboxlist Get data from database

#1 User is offline   genio 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 07-December 17

Posted 07 December 2017 - 11:52 AM

--> form
<?= $form->field($model, 'DIVISI_ID',[
      'template' => "<center><label>{label}</label></center><center><div style='width:400px'>{input}</div><center>"
    ])->checkboxList(ArrayHelper::map(KategoriDivisi::find()->all(), 'DIVISI_ID', 'DIVISI_NAMA')) ?>


--> Controller
public function actionCreate()
    {
        $model = new KategoriDivisi();

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect(['view', 'id' => $model->DIVISI_ID]);
        } else {
            return $this->render('create', [
                'model' => $model,
            ]);
        }
    }


How to change data value to string? and save in table when data is checked?
0

#2 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 3,411
  • Joined: 16-February 11
  • Location:Japan

Posted 07 December 2017 - 05:30 PM

Hi genio, welcome to the forum.

One of the key points is that you have to create a model that can handle an array of IDs when you want to use a checkbox list.

I hope the following wiki article might be a help. It's a bit long, and it might not be a straight answer to your current issue, but try it please.

Wiki : Yii 2.0: How to create/update a model with its related items using Listbox or CheckboxList
http://www.yiiframew...or-checkboxlist
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users