コード例 #1
0
ファイル: MenuComponent.php プロジェクト: JoHein/LeBonCoup
 /**
  * add
  *
  * Adds a new menu-item.
  *
  * ### OPTIONS
  * - id
  * - parent
  * - url
  * - title
  * - icon
  * - area
  * - weight
  *
  * @param string $title The title or id of the item.
  * @param array $item Options for the item.
  * @return void
  */
 public function add($title, $item = [])
 {
     $list = self::$data;
     $_item = ['id' => $title, 'parent' => false, 'url' => '#', 'title' => $title, 'icon' => '', 'area' => $this->area(), 'active' => false, 'weight' => 10, 'children' => []];
     $item = array_merge($_item, $item);
     $url = Router::url($item['url']);
     $actives = $this->config('active');
     if ($url === Router::url("/" . $this->Controller->request->url)) {
         $item['active'] = true;
     }
     $this->area = $item['area'];
     $data = self::$data;
     if (array_key_exists($this->area, $data)) {
         $menu = $data[$this->area];
     } else {
         $menu = [];
     }
     if ($item['parent']) {
         if (array_key_exists($item['parent'], $menu)) {
             $menu[$item['parent']]['children'][$item['id']] = $item;
         }
     } else {
         $menu[$item['id']] = $item;
     }
     $menu = Hash::sort($menu, '{s}.weight', 'asc');
     $data[$this->area] = $menu;
     self::$data = $data;
 }
コード例 #2
0
 /**
  * add
  *
  * Adds a new menu-item.
  *
  * ### OPTIONS
  * - id
  * - parent
  * - url
  * - title
  * - icon
  * - area
  * - weight
  *
  * @param string $title The title or id of the item.
  * @param array $item Options for the item.
  * @return void
  */
 public function add($title, $item = [])
 {
     $list = self::$data;
     $_item = ['id' => $title, 'parent' => false, 'url' => '#', 'title' => $title, 'icon' => '', 'area' => $this->area(), 'active' => false, 'weight' => 10, ''];
     $item = array_merge($_item, $item);
     $url = Router::url($item['url']);
     $actives = $this->config('active');
     if ($url === "/" . $this->Controller->request->url) {
         $item['active'] = true;
     }
     $this->area = $item['area'];
     $data = self::$data;
     $data[$this->area][$item['id']] = $item;
     $data[$this->area] = Hash::sort($data[$this->area], '{s}.weight', 'asc');
     self::$data = $data;
 }