title: cakePHP - function which can be called after any controller action executes
body: <p>I need a function which can be called after any controller method executes.</p>
  
  <p>Forexample, <code>beforeFilter()</code> in App controller is always called before any controller action is executed, similarly I need something like <code>afterFilter()</code>.</p>
  
  <p>The problem with <code>afterFilter()</code> is that is executing before the controller action.</p>
  
  <p>I have a controller name <code>TestController</code> and an action <code>test()</code>, with the following code:</p>
  
  <p><strong>TestController.php</strong></p>
  
  <pre><code>function test() {
      echo 'test';exit;
  }
  </code></pre>
  
  <p>And inside <code>afterFilter()</code> I put this code:</p>
  
  <p><strong>AppController.php</strong></p>
  
  <pre><code>function afterFilter() {
      echo 'afterfilter';exit;
  }
  </code></pre>
  
  <p>then only <code>afterFilter()</code> executes.</p>
  
  <p>On commenting the above line, as follows:</p>
  
  <pre><code>function afterFilter() {
      //echo 'afterfilter';exit;
  }
  </code></pre>
  
  <p><code>TestController:test()</code> executes. So <code>afterFilter()</code> is getting called before the controller method. I need a function which is called after it, irrespective of the controller name or action name.</p>