From 1de5fee5bb6c3938a52feb46ea8539ae478ef98b Mon Sep 17 00:00:00 2001
From: nate <nate@cakephp.org>
Date: Sat, 12 Aug 2006 01:18:28 +0000
Subject: [PATCH] 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
---
 cake/libs/view/view.php | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/cake/libs/view/view.php b/cake/libs/view/view.php
index f25a26bf1..c3dcc2a90 100644
--- a/cake/libs/view/view.php
+++ b/cake/libs/view/view.php
@@ -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.
  *