【CakePHP2.x】render()でViewを使いまわす。

システムで登録画面と編集画面など、
レイアウトが似ている画面を使いまわす時は
コントローラーで $this->render() を使うと、
Viewを指定できる。

以下のようにすると、add.ctp を edit でも使用可能になる。

public function edit{
    $this->render('add');
}

注意点として、$this->render() を実行する前に、
$this->set() を実行しておかないと View に変数が反映されない点がある。

以下では $message が View に反映されない。

public function edit{
    $this->render('add');
    $this->set('message', 'hello!');
}


以下のようにすればOK。

public function edit{
    $this->set('message', 'hello!');
    $this->render('add');
}