title: checkboxlist multiple selection in db yii2?
body: <p>Learned a lot about my question, and didn't figure it out. I need to write two or more values in the database from <code>checkboxList()</code>
  In my view <code>activeForm</code></p>
  
  <pre><code>&lt;?= $form-&gt;field($model, 'quant[]')-&gt;checkboxList([
                          'one' =&gt; 'one',
                          'two' =&gt; 'two',
                          'three' =&gt; 'three',
                          'four' =&gt; 'four'], 
                          ['separator' =&gt; '&lt;br&gt;']); ?&gt;
  </code></pre>
  
  <p>So after create no matter how much values I choose, only one will add in db. 
  I realized that I need to get an array in the controller and then it will save in the database. Something like this:</p>
  
  <pre><code> public function actionCreate()
      {
  
          $model = new TakMol();
  
          if ($model-&gt;load(Yii::$app-&gt;request-&gt;post()) &amp;&amp; $model-&gt;save()) {
              $model-&gt;quant=implode(',',$_POST['TakMol']['quant']); //change items into string to be saved
  
              return $this-&gt;redirect(['index']);
  
          } else {
              $model-&gt;quant=explode(',',$model-&gt;quant); //string to array to fill the checkboxlist
  
              return $this-&gt;render('create', [
                  'model' =&gt; $model,
  
              ]);
          }
  
      }
  </code></pre>
  
  <p>Maybe I need to do something like this in <code>actionCreate</code></p>
  
  <pre><code>$post=Yii::$app-&gt;request-&gt;post();
          $checkbox = array_keys ($post);
          foreach ($checkbox as $value){
              $model = new TakMol();              
                       $model-&gt;quant = $model-&gt;id;  
                       $model-&gt;quant = $value;
                       $model-&gt;save();
          }
  </code></pre>
  
  <p>I tried and other options, it didn't work out. I will be grateful for help in solving.</p>
  
  <p><a href="https://i.stack.imgur.com/Jwlqu.jpg" rel="nofollow noreferrer"><strong>_form(cell)</strong></a>  <a href="https://i.stack.imgur.com/0IXXM.jpg" rel="nofollow noreferrer"><strong>index(cell)</strong></a></p>