예제 #1
0
파일: View.php 프로젝트: sherix88/sigedu
/**
 * Renders a layout. Returns output from _render(). Returns false on error.
 * Several variables are created for use in layout.
 *
 * - `title_for_layout` - A backwards compatible place holder, you should set this value if you want more control.
 * - `content_for_layout` - contains rendered view file
 * - `scripts_for_layout` - contains scripts added to header
 *
 * @param string $content_for_layout Content to render in a view, wrapped by the surrounding layout.
 * @param string $layout Layout name
 * @return mixed Rendered output, or false on error
 * @throws CakeException if there is an error in the view.
 */
	public function renderLayout($content_for_layout, $layout = null) {
		$layoutFileName = $this->_getLayoutFileName($layout);
		if (empty($layoutFileName)) {
			return $this->output;
		}
		if (!$this->_helpersLoaded) {
			$this->loadHelpers();
		}
		$this->Helpers->trigger('beforeLayout', array($layoutFileName));

		$this->viewVars = array_merge($this->viewVars, array(
			'content_for_layout' => $content_for_layout,
			'scripts_for_layout' => implode("\n\t", $this->_scripts),
		));

		if (!isset($this->viewVars['title_for_layout'])) {
			$this->viewVars['title_for_layout'] = Inflector::humanize($this->viewPath);
		}

		$this->output = $this->_render($layoutFileName);

		if ($this->output === false) {
			throw new CakeException(__d('cake_dev', "Error in layout %s, got no content.", $layoutFileName));
		}

		$this->Helpers->trigger('afterLayout', array($layoutFileName));
		return $this->output;
	}