Set CakePHP layouts in app_controller

Fed up of writing $this->layout = ‘admin’ in all the admin methods of your controllers? Me too.

I realised that instead you could automatically set them in the beforeFilter() of your app_controller instead.

function beforeFilter(){

  if(isset($this->params['prefix'])) {
    //read the admin prefix set in core.php
    $admin = Configure::read('Routing.admin'); 

    if($this->params['prefix'] == $admin){
      $this->layout = $admin;

If you need to over-ride this, you can just do so as normal in individual methods.