Answers.Body: <p>If you're just looking to return <code>true</code> or an error message from your controller's action, then it should probably be something like:</p>
  
  <pre><code>$this-&gt;returnJson(array('success' =&gt; true));
  </code></pre>
  
  <p>Or on error:</p>
  
  <pre><code>$this-&gt;returnErrorJson($e-&gt;getMessage());
  </code></pre>
  
  <p><code>returnErrorJson</code> will set an <code>'error'</code> key and pass whatever mess you use as its value.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-11-08T21:27:08.443Z
Answers.LastActivityDate: 2016-11-08T21:27:08.443Z
Answers.UserDisplayName: Brad Bell
Body: <p>Simple question: I made a button in my plugin settings that creates a <code>Craft.postActionRequest</code> but what should the controller return?</p>
  
  <p>It does not need to return anything else than true (successful) or string (action was not successful ->  errormessage) but if I return a true or a false or anything else than a template to render I get an error...</p>
  
  <p>Little example:<br>
  my template is just</p>
  
  <pre><code>{{ response }}
  </code></pre>
  
  <p>And my controller</p>
  
  <pre><code>//correct -&gt; no error, this template is just empty
  public function actionDeleteAccessToken(){
      return $this-&gt;renderTemplate('srgoogleanalytics/tools/empty', array(response =&gt; true));
  }
  </code></pre>
  
  <p>but if I make something like this</p>
  
  <pre><code>public function actionDeleteAccessToken(){
      return true;
  }
  </code></pre>
  
  <p>I receive a PHP error file not found.
  What do I wrong?</p>
  
Tags: <plugin-development><controller>
Title: What should my controller return in a Craft.postActionRequest
ThreadText: # What should my controller return in a Craft.postActionRequest
  
  (Asked by: username_0 on 2016-11-08)
  
  Simple question: I made a button in my plugin settings that creates a `Craft.postActionRequest` but what should the controller return?
  
  It does not need to return anything else than true (successful) or string (action was not successful -> errormessage) but if I return a true or a false or anything else than a template to render I get an error...
  
  Little example:  
  my template is just
  
  ```
  {{ response }}
  
  ```
  
  And my controller
  
  ```
  //correct -> no error, this template is just empty
  public function actionDeleteAccessToken(){
      return $this->renderTemplate('srgoogleanalytics/tools/empty', array(response => true));
  }
  
  ```
  
  but if I make something like this
  
  ```
  public function actionDeleteAccessToken(){
      return true;
  }
  
  ```
  
  I receive a PHP error file not found.
  What do I wrong?
  
  **Tags:** plugin-development, controller
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-11-08. Score: 5 | Accepted answer
  
  If you're just looking to return `true` or an error message from your controller's action, then it should probably be something like:
  
  ```
  $this->returnJson(array('success' => true));
  
  ```
  
  Or on error:
  
  ```
  $this->returnErrorJson($e->getMessage());
  
  ```
  
  `returnErrorJson` will set an `'error'` key and pass whatever mess you use as its value.
  
  
  ---
  
  