調べました。
きっかけ
cakephp2の勉強やってて、default.ctpに書かれている$this->fetchメソッドがよく分からず調べていたものの、assignで書き換えられるよ!って話しか無くて、どこにあるんだ!って思ってげきおこになったので調べた。
使用したCakePHPのバージョン
2.6.1です。
記述されているファイル
該当の記述があるのは、lib\Cake\View\View.phpです。
このファイルの500行目くらいにあるrenderLayoutメソッドです。
public function renderLayout($content, $layout = null) {
$layoutFileName = $this->_getLayoutFileName($layout);
if (empty($layoutFileName)) {
return $this->Blocks->get('content');
}
if (empty($content)) {
$content = $this->Blocks->get('content');
} else {
$this->Blocks->set('content', $content);
}
$this->getEventManager()->dispatch(new CakeEvent('View.beforeLayout', $this, array($layoutFileName)));
$scripts = implode("\n\t", $this->_scripts);
$scripts .= $this->Blocks->get('meta') . $this->Blocks->get('css') . $this->Blocks->get('script');
$this->viewVars = array_merge($this->viewVars, array(
'content_for_layout' => $content,
'scripts_for_layout' => $scripts,
));
$title = $this->Blocks->get('title');
if ($title === '') {
if (isset($this->viewVars['title_for_layout'])) {
$title = $this->viewVars['title_for_layout'];
} else {
$title = Inflector::humanize($this->viewPath);
}
}
$this->viewVars['title_for_layout'] = $title;
$this->Blocks->set('title', $title);
$this->_currentType = self::TYPE_LAYOUT;
$this->Blocks->set('content', $this->_render($layoutFileName));
$this->getEventManager()->dispatch(new CakeEvent('View.afterLayout', $this, array($layoutFileName)));
return $this->Blocks->get('content');
}
上記にある、$this->Blocks->setというメソッドがassignの役割を果たしています。
そもそもfetchとかassignはViewBlockの機能なのです。
このように定義されていることが分かったので良かったです。