title: Yii2 How to properly create checkbox column in gridview for bulk actions?
body: <p>I need to create "bulk actions" similar to wordpress posts management, so you can for example delete multiple records at a time. </p>
  
  <p>This is my approach, and works fine, but I'm sure it is not the best approach, since this method is vulnerable to CSRF hacks. </p>
  
  <p>Checkbox column in a gridview:</p>
  
  <pre><code>GridView::widget([
  'dataProvider' =&gt; $dataProvider,    
  'columns' =&gt; [
  ['class' =&gt; 'yii\grid\CheckboxColumn'],
  'id'=&gt;'grid',
  'country',
  ],
  ]); 
  </code></pre>
  
  <p>Button that fires a function</p>
  
  <pre><code>&lt;a href="#" onclick="bulkAction('p');"&gt;
  </code></pre>
  
  <p>The function:</p>
  
  <pre><code>&lt;script&gt;
      function bulkAction(a) {
          var keys = $('#grid').yiiGridView('getSelectedRows');
          window.location.href='&lt;?php echo Url::to(['mycontroller/bulk']); ?&gt;&amp;action='+a+'&amp;ids='+keys.join();
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>This function creates a url like this: </p>
  
  <pre><code>index.php?r=mycontroller/bulk&amp;action=1&amp;ids=2,6,7,8
  </code></pre>
  
  <p>PROBLEM IS
  This approach is vulnerable to CSRF hacks (explained here: <a href="http://blog.codinghorror.com/cross-site-request-forgeries-and-you/" rel="noreferrer">http://blog.codinghorror.com/cross-site-request-forgeries-and-you/</a>)</p>
  
  <p>So, what is the PROPER way to do it?</p>