title: How to post actual primary keys of records from table and not indexes of an array in php Yii2 if I use select2 widget?
body: <p>My function inside controller is as follows:</p>
  <pre><code>public function actionProjects($id)
      {
          $model = $this-&gt;findModel($id);
          $projects = Project::find()-&gt;all();
          $projectIds = Yii::$app-&gt;request-&gt;post('projects');
          if (Yii::$app-&gt;request-&gt;isPost) {
              Yii::$app-&gt;session-&gt;setFlash('success');
              $model-&gt;unlinkAll('projects');
              if ($projectIds) {
                  foreach ($projectIds as $projectId) {
                      $project = Project::findOne(abs((int)$projectId));
                      if ($project) {
                          $model-&gt;link('projects', $project);
                      }
                  }
              }
          }
          print_r($projectIds);
          return $this-&gt;render('projects', ['projects' =&gt; $projects, 'model' =&gt; $model]);
      }
  </code></pre>
  <p>My view is as follows:</p>
  <pre><code>&lt;?php
  ...
  function sortArray($a, $b)
  {
      return strcmp($a, $b);
  }
  
  $projects = ArrayHelper::map($projects, 'id', 'title');
  usort($projects, 'sortArray');
  ?&gt;
  &lt;div class=&quot;application-create x_panel&quot;&gt;
  
      &lt;div class=&quot;x_title&quot;&gt;&lt;h3&gt;&lt;?= Html::encode($this-&gt;title) ?&gt;&lt;/h3&gt;&lt;/div&gt;
  
      &lt;div class=&quot;x_content&quot;&gt;
          &lt;?php $form = ActiveForm::begin(); ?&gt;
          &lt;div class=&quot;form-group&quot;&gt;
              &lt;?= Select2::widget([
                  'name' =&gt; 'projects[]',
                  'options' =&gt; ['placeholder' =&gt; 'Выберите проект...'],
                  'language' =&gt; 'ru',
                  'value' =&gt; array_keys(ArrayHelper::map($model-&gt;projects, 'id', 'title')),
                  'data' =&gt; $projects,
                  'pluginOptions' =&gt; [
                      'allowClear' =&gt; true,
                      'multiple' =&gt; true
                  ],
              ]) ?&gt;
          &lt;/div&gt;
          &lt;div class=&quot;form-group&quot;&gt;
              &lt;?= Html::submitButton('Обновить', ['class' =&gt; 'btn btn-primary']) ?&gt;
          &lt;/div&gt;
          &lt;?php ActiveForm::end() ?&gt;
      &lt;/div&gt;
  
  &lt;/div&gt;
  </code></pre>
  <p>When I select single or multiple items from select2, and click update button -  this code:</p>
  <pre><code>$projectIds = Yii::$app-&gt;request-&gt;post('projects');
  </code></pre>
  <p>posts array like this:  <code>Array ( [0] =&gt; 0 [1] =&gt; 1 [2] =&gt; 2 )</code></p>
  <p>the data sent to the server is the array of indexes of items and not actual indexes (primary keys) from the table. (I have 3 items in db table - their indexes are 5,6 and 7)</p>
  <p>How to sent primary keys of selected items?  I cannot find hidden rat that causes my problem. It seems that everything is correct in code. But actually not.</p>