<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -58,7 +58,12 @@ class MenuComponent extends Object {
  * @var string  String compatible with strtotime.
  */
 	public $cacheTime = '+1 day';
-	
+/**
+ * cache config key
+ *
+ * @var string
+ */
+	public $cacheConfig = 'menu_component';
 /**
  * Separator between controller and action name.
  *
@@ -107,7 +112,6 @@ class MenuComponent extends Object {
  */
 	protected $_rebuildMenus = false;
 
-
 /**
  * initialize function
  *
@@ -134,6 +138,8 @@ class MenuComponent extends Object {
 	public function startup(&amp;$Controller) {
 		$this-&gt;Controller =&amp; $Controller;
 		
+		Cache::config($this-&gt;cacheConfig, array('engine' =&gt; 'File', 'duration' =&gt; $this-&gt;cacheTime, 'prefix' =&gt; $this-&gt;cacheKey));
+		
 		//no active session, no menu can be generated
 		if (!$this-&gt;Auth-&gt;user()) {
 			return;
@@ -154,8 +160,7 @@ class MenuComponent extends Object {
 		$data = array(
 			'menus' =&gt; $this-&gt;rawMenus
 		);
-		Cache::set(array('duration' =&gt; $this-&gt;cacheTime));
-		if (Cache::write($this-&gt;cacheKey, $data)) {
+		if (Cache::write($this-&gt;cacheKey, $data, $this-&gt;cacheConfig)) {
 			return true;
 		}
 		$this-&gt;log('Menu Component - Could not write Menu cache.');
@@ -168,8 +173,8 @@ class MenuComponent extends Object {
  * @return boolean true if cache was loaded.
  */
 	public function loadCache() {
-		Cache::set(array('duration' =&gt; $this-&gt;cacheTime));
-		if ($data = Cache::read($this-&gt;cacheKey)) {
+		//Cache::set(array('duration' =&gt; $this-&gt;cacheTime));
+		if ($data = Cache::read($this-&gt;cacheKey, $this-&gt;cacheConfig)) {
 			$this-&gt;rawMenus = $this-&gt;_mergeMenuCache($data['menus']);
 			return true;
 		}
@@ -184,7 +189,7 @@ class MenuComponent extends Object {
  * @return boolean
  **/
 	public function clearCache() {
-		return Cache::delete($this-&gt;cacheKey);
+		return Cache::delete($this-&gt;cacheKey, $this-&gt;cacheConfig);
 	}
 
 /**
@@ -199,8 +204,7 @@ class MenuComponent extends Object {
 			$aroKey = key($aro) . $aro[key($aro)]['id'];
 		}
 		$cacheKey = $aroKey . '_' . $this-&gt;cacheKey;
-		Cache::set(array('duration' =&gt; $this-&gt;cacheTime));
-		$completeMenu = Cache::read($cacheKey);
+		$completeMenu = Cache::read($cacheKey, $this-&gt;cacheConfig);
 		if (!$completeMenu || $this-&gt;_rebuildMenus == true) {
 			$this-&gt;generateRawMenus();
 			$menu = array();
@@ -218,8 +222,7 @@ class MenuComponent extends Object {
 				}
 			}
 			$completeMenu = $this-&gt;_formatMenu($menu);
-			Cache::set(array('duration' =&gt; $this-&gt;cacheTime));
-			Cache::write($cacheKey, $completeMenu);
+			Cache::write($cacheKey, $completeMenu, $this-&gt;cacheConfig);
 		}
 		$this-&gt;menu = $completeMenu;
 	}
@@ -240,7 +243,6 @@ class MenuComponent extends Object {
 	public function generateRawMenus() {
 		$Controllers = $this-&gt;getControllers();
 		$cakeAdmin = Configure::read('Routing.admin');
-		
 		$this-&gt;createExclusions();
 		
 		//go through the controllers folder and make an array of every menu that could be used.
@@ -280,7 +282,7 @@ class MenuComponent extends Object {
 					$url[$cakeAdmin] = false;
 				}
 				if (strpos($action, $cakeAdmin . '_') !== false &amp;&amp; $cakeAdmin) {
-					$url['admin'] = true;
+					$url[$cakeAdmin] = true;
 					$adminController = true;
 				}
 
@@ -290,6 +292,7 @@ class MenuComponent extends Object {
 					'id' =&gt; $this-&gt;_createId($ctrlCamel, $action),
 					'title' =&gt; $human,
 					'url' =&gt; $url,
+					'weight' =&gt; 0,
 				);
 			}
 			if ($menuOptions['controllerButton']) {
@@ -305,6 +308,7 @@ class MenuComponent extends Object {
 					'id' =&gt; $ctrlCamel,
 					'title' =&gt; $ctrlHuman,
 					'url' =&gt; $url,
+					'weight' =&gt; 0
 				);
 				$this-&gt;rawMenus[] = $menuItem;
 			}
@@ -390,6 +394,7 @@ class MenuComponent extends Object {
 			'url' =&gt; null,
 			'parent' =&gt; null,
 			'id' =&gt; null,
+			'weight' =&gt; 0,
 		);
 		$menu = array_merge($defaults, $menu);
 		if (!$menu['id'] &amp;&amp; isset($menu['url'])) {
@@ -447,10 +452,22 @@ class MenuComponent extends Object {
 				$out[] =&amp; $idMap[$id];
 			}
 		}
+		usort($out, array(&amp;$this, '_sortMenu'));
 		return $out;
 	}
 
 /**
+ * Sort the menu before returning it. Used with usort()
+ *
+ * @return int
+ **/
+	protected function _sortMenu($one, $two) {
+		if ($one['weight'] == $two['weight']) {
+			return 1;
+		}
+		return ($one['weight'] &lt; $two['weight']) ? -1 : 1;
+	}
+/**
  * Merge the Cached menus with the Menus added in Controller::beforeFilter to ensure they are unique.
  *
  * @param array $cachedMenus</diff>
      <filename>cakephp/components/menu/menu.php</filename>
    </modified>
    <modified>
      <diff>@@ -131,6 +131,7 @@ class MenuComponentTestCase extends CakeTestCase {
 			'id' =&gt; 'posts-delete',
 			'parent' =&gt; null,
 			'title' =&gt; 'Delete',
+			'weight' =&gt; 0
 		);
 		$this-&gt;assertEqual($this-&gt;Menu-&gt;rawMenus[0], $expected);
 		$this-&gt;Menu-&gt;rawMenus = array();
@@ -141,7 +142,8 @@ class MenuComponentTestCase extends CakeTestCase {
 				'action' =&gt; 'delete',
 			),
 			'id' =&gt; 'funky-id',
-			'parent' =&gt; 'posts'
+			'parent' =&gt; 'posts',
+			'weight' =&gt; 0
 		);
 		$this-&gt;Menu-&gt;addMenu($menu);
 		$expected = array(
@@ -152,6 +154,7 @@ class MenuComponentTestCase extends CakeTestCase {
 			'id' =&gt; 'funky-id',
 			'parent' =&gt; 'posts',
 			'title' =&gt; 'Delete',
+			'weight' =&gt; 0
 		);
 		$this-&gt;assertEqual($this-&gt;Menu-&gt;rawMenus[0], $expected);
 		$this-&gt;Menu-&gt;rawMenus = array();
@@ -342,6 +345,7 @@ class MenuComponentTestCase extends CakeTestCase {
 				'admin' =&gt; false,
 			),
 			'title' =&gt; 'Action1',
+			'weight' =&gt; 0,
 			'children' =&gt; array(),
 		);
 		$this-&gt;assertEqual($result[1]['children'][0], $expected);
@@ -365,6 +369,7 @@ class MenuComponentTestCase extends CakeTestCase {
 				'admin' =&gt; false,
 			),
 			'title' =&gt; 'Action1',
+			'weight' =&gt; 0
 		);
 		$this-&gt;assertEqual($result[0], $expected);
 
@@ -377,9 +382,50 @@ class MenuComponentTestCase extends CakeTestCase {
 				'admin' =&gt; false,
 			),
 			'title' =&gt; 'Controller1',
+			'weight' =&gt; 0,
 		);
 		$this-&gt;assertEqual($result[2], $expected);
 	}
+/**
+ * test Sorting by weight.
+ *
+ * @access public
+ * @return void
+ */	
+	function testWeightSorting() {
+		$this-&gt;Menu-&gt;Acl-&gt;setReturnValue('check', true);
+		$this-&gt;Menu-&gt;addMenu(array(
+			'title' =&gt; 'First',
+			'url' =&gt; array(
+				'controller' =&gt; 'posts',
+				'action' =&gt; 'delete'
+			),
+			'weight' =&gt; 1,
+		));
+		$this-&gt;Menu-&gt;addMenu(array(
+			'title' =&gt; 'Third',
+			'url' =&gt; array(
+				'controller' =&gt; 'posts',
+				'action' =&gt; 'more_stuff'
+			),
+			'weight' =&gt; 4,
+		));
+		$this-&gt;Menu-&gt;addMenu(array(
+			'title' =&gt; 'Second',
+			'url' =&gt; array(
+				'controller' =&gt; 'posts',
+				'action' =&gt; 'do_stuff'
+			),
+			'weight' =&gt; 2,
+		));
+		$this-&gt;Menu-&gt;constructMenu(array('User' =&gt; array('id' =&gt; 1)));
+		$result = $this-&gt;Menu-&gt;menu;
+		$this-&gt;assertEqual($result[2]['title'], 'First');
+		$this-&gt;assertEqual($result[3]['title'], 'Second');
+		$this-&gt;assertEqual($result[4]['title'], 'Third');
+
+		Cache::delete('User1_'.$this-&gt;Menu-&gt;cacheKey);
+	}
 	
 	function tearDown() {
 		ClassRegistry::flush();</diff>
      <filename>cakephp/components/menu/menu.test.php</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>ddef20fdcae41ef7645c73ccc5e4aa4add1b0ea6</id>
    </parent>
  </parents>
  <author>
    <name>Mark Story</name>
    <email>mark@mark-story.com</email>
  </author>
  <url>http://github.com/markstory/story-scribbles/commit/225e0b526935f2f4b24d60259facbc35bd6bbfee</url>
  <id>225e0b526935f2f4b24d60259facbc35bd6bbfee</id>
  <committed-date>2008-12-18T18:40:08-08:00</committed-date>
  <authored-date>2008-12-18T18:40:08-08:00</authored-date>
  <message>Adding weighting to the Menus. Added menu elements can have weights
applied heavier items sink.</message>
  <tree>2af7bbea5250f1944285479221afec5983eb5d90</tree>
  <committer>
    <name>Mark Story</name>
    <email>mark@mark-story.com</email>
  </committer>
</commit>
