Adding View::set(), allowing templates/elements to set variables for layout

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@3396 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2006-08-12 01:18:28 +00:00
parent 8622b6f9ce
commit 1de5fee5bb

View file

@ -437,6 +437,41 @@ class View extends Object{
$this->layout = $layout; $this->layout = $layout;
} }
/**
* Allows a template or element to set a variable that will be available in
* a layout or other element. Analagous to Controller::set.
*
* @param mixed $one A string or an array of data.
* @param mixed $two Value in case $one is a string (which then works as the key).
* Unused if $one is an associative array, otherwise serves as the values to $one's keys.
* @return unknown
*/
function set($one, $two = null) {
$data = null;
if (is_array($one)) {
if (is_array($two)) {
$data = array_combine($one, $two);
} else {
$data = $one;
}
} else {
$data = array($one => $two);
}
if ($data == null) {
return false;
}
foreach($data as $name => $value) {
if ($name == 'title') {
$this->pageTitle = $value;
} else {
$this->_viewVars[$name] = $value;
}
}
}
/** /**
* Displays an error page to the user. Uses layouts/error.html to render the page. * Displays an error page to the user. Uses layouts/error.html to render the page.
* *