title: Yii2 Allow action access only by POST request
body: <p>I have created a yii2 controller, which meant to display statistics from database, for a specific user. There is a ajax request, performed to my controller action, but i want to restrict to allow only POST method for this action.</p>
  
  <pre><code>&lt;?php
  use yii\web\Response;
  namespace app\controllers;
  
  use Yii;
  use yii\filters\AccessControl;
  use yii\web\Controller;
  use yii\web\Response;
  use yii\filters\VerbFilter;
  use app\models\StatsModel;
  
  class DataController extends Controller
  {
      /**
       * {@inheritdoc}
       */
      public function behaviors()
      {
          return [
          [
              'class' =&gt; 'yii\filters\ContentNegotiator',
              'only' =&gt; ['stats'],
               'formats' =&gt; [
                  'application/json' =&gt; Response::FORMAT_JSON 
                ],                
             ],
         ];
      }
  
      /**
       * {@inheritdoc}
       */
      public function actions()
      {
          return [
              'error' =&gt; [
                  'class' =&gt; 'yii\web\ErrorAction',
              ],
              'captcha' =&gt; [
                  'class' =&gt; 'yii\captcha\CaptchaAction',
                  'fixedVerifyCode' =&gt; YII_ENV_TEST ? 'testme' : null,
              ],
          ];
      }
  
      public function actionStats()
      {   
           //how can i restrict this action to only POST http method?
           return StatsModel::find()-&gt;all();
      }
  }
  </code></pre>
  
  <p>I need to restrict <code>actionStats()</code> to HTTP Post method only.</p>