title: Yii Framework 2.0 check if it is a GET request from AJAX
body: <p>Working with Yii framework 2.0, I have an AJAX GET jQuery script that points to a function in a controller class.</p>
  
  <pre><code>$.get('localhost/website/index', {param: 'xxxx'}, function(returnedData){
      // some code here.....
  }, 'json');
  </code></pre>
  
  <p>In the controller class I have a method as following that handles the AJAX GET request.</p>
  
  <pre><code>public function actionIndex() {
       $getParam = $_GET['param'];
       // echo $getParam is: 'xxxx'.
  
       // some other code here....
  
       echo json_encode(array());
  }
  </code></pre>
  
  <p>Everything works fine when executing this AJAX GET jQuery script. But if I visit the link <strong><em>localhost/website/index</em></strong> manually on the web browser, I get the following error.</p>
  
  <pre><code>PHP Notice - ErrorException
  Undefined index: param
  
  // the code snippet is also being shown.....
  </code></pre>
  
  <p>I don't want any users to see this error in case they know this link and visit this link by accident or on purpose. If I use</p>
  
  <pre><code>if($_GET['param']){...}
  </code></pre>
  
  <p>I still get the error message on the browser. How can I solve that?</p>