0

My default layout is default.ctp, but I want to use another layout default-scaffolds.ctp only for scaffolding views, when I use in the controller:

public $scaffold;

I tried in the AppController

    public function beforeScaffold() {
        $this->layout = 'default-scaffolds';
}

but that didn't work.

I appreciate any help with this.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
mart
  • 354
  • 3
  • 14

3 Answers3

3

I was just facing the same problem and solved it by specifying router prefix 'admin', setting up

public $scaffold = 'admin';

in the controller and in the AppController I added to the beforeFilter() method

public function beforeFilter() {
  if ($this->request->prefix == 'admin') {
    $this->layout = 'scaffold';
  } 
}
stepanbujnak
  • 651
  • 6
  • 16
1

Add this beforeRender()

public function beforeRender() {
    if (in_array($this->request->action, array('index', 'add', 'view', 'edit'))) {
        $this->layout = 'default-scaffolds';
    }
}
Teej
  • 12,764
  • 9
  • 72
  • 93
  • that works for me only when the actions (index, add, view, edit) exist and when the views exist. But what i want is use it with public $scaffold; – mart Nov 24 '12 at 09:49
0

Alternatively, in lib/Cake/Controller/Scaffold.php, in line 377 (the _scaffold(CakeRequest $request)-function, within this if: if (in_array($request->params['action'], $this->scaffoldActions)), just add the following line:

$this->layout = 'default_scaffold'; // this is a custom-added line in order to activate the default CSS file when scaffolding

And add default_scaffold.ctp to your Layout folder.

arik
  • 28,170
  • 36
  • 100
  • 156