title: CakePHP: Global Redirect
body: <p>In some parts of the application, a user can do some bad things by changing a URL. For example, let's say they'd change the request for an edit.</p>
  
  <p><a href="http://website.com/edit/4000" rel="nofollow">http://website.com/edit/4000</a></p>
  
  <p>But they do not own post 4000, the only way they could have gotten there is through URL manipulation.</p>
  
  <p>In these cases, I want to simply redirect them to the home page. However, if I trigger one of these catches, I want to display myself a message. (so it's not just a matter of a simple redirect)</p>
  
  <p>I put this in the bootstrap.</p>
  
  <pre><code>function security_redirect ($msg) {
      if ((not_an_admin) == 1) {
         $this-&gt;redirect(array('controller' =&gt; 'site', 'action' =&gt; 'index'));
      } else {
          die($msg);
      }
  }
  </code></pre>
  
  <p>I get the error message:</p>
  
  <pre><code>Using $this when not in object context
  </code></pre>
  
  <p>When I perform:</p>
  
  <pre><code>security_redirect("Tried to edit a post that isn't yours!");
  </code></pre>
  
  <p>What can I do? What am I doing wrong? I don't see why it's not considered to be inside an object... but maybe it's obvious.</p>