mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
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:
parent
8622b6f9ce
commit
1de5fee5bb
1 changed files with 35 additions and 0 deletions
|
@ -437,6 +437,41 @@ class View extends Object{
|
|||
$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.
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue