Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>By setting <code>'prefix' =&gt; 'admin'</code> you are telling CakePHP that you want to use a prefix of <code>admin</code> for that route; basically meaning you want to use controller actions and views that have names prefixed with <code>admin_</code>. This part you are already aware of, and things will probably work fine with just this.</p> <p>When creating routes though, any array keys passed into the second argument that aren't recognised by CakePHP (ie. not your usual <code>controller</code>, <code>action</code>, <code>plugin</code>, <code>prefix</code> stuff) are set as named parameters during requests matching that route.</p> <p>Adding <code>'admin' =&gt; true</code> is therefore just a named parameter in this case, but it comes with its advantages. Firstly, it can make code more succinct.</p> <pre><code>/* Determine if a request came through admin routing */ // without: if ($this-&gt;params['prefix'] == 'admin') {} // with: if ($this-&gt;params['admin']) {} /* Create a link that is reverse-routed to an admin prefixed route */ // without: $html-&gt;link('...', array('prefix' =&gt; 'admin', 'controller' =&gt; 'users')); // with: $html-&gt;link('...', array('admin' =&gt; true, 'controller' =&gt; 'users')); </code></pre> <p>Secondly, it provides backwards compatibility with the way admin routing worked in CakePHP 1.2 (the last line from the above example is how you would have made admin routing links in 1.2). Therefore, developers migrating from 1.2 to 1.3 can prevent having to change links throughout their application by keeping the <code>'admin' =&gt; true</code> flag in their routes (and adding the <code>'prefix' =&gt; 'admin'</code> one).</p> <p>Lastly, by setting a custom flag like this with a named parameter and using it in your application instead of referencing your route by an exact string means that you prevent yourself from ever having to change links if you change the prefix to something else (say from <code>admin</code> to <code>administrator</code> or <code>edit</code>)... although this is sort of a moot point, as you would need to rename all your <code>admin_*</code> controller actions and views. :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload