コード例 #1
0
 public function generateMenu()
 {
     $menu = new ioMenu();
     if ($this->getCurrentApp() == Menu::FRONTEND_APP) {
         $routings = sfYaml::load(sfConfig::get('sf_apps_dir') . '/' . Menu::FRONTEND_APP . '/config/routing.yml');
     } else {
         $routings = sfYaml::load(sfConfig::get('sf_apps_dir') . '/' . Menu::BACKEND_APP . '/config/routing.yml');
     }
     foreach ($this->getItems() as $item) {
         foreach ($routings as $key => $routing) {
             if ("@" . $key == $item->routing) {
                 if (!empty($item->section)) {
                     //Set class "active" if the item is a link to the current page
                     if ($menu->getChild($item->section, false) == null) {
                         $menu->addChild($item->section, $item->section_routing)->setLinkOptions(array('class' => 'link'));
                     }
                     $menu->getChild($item->section)->addChild($item->text, $item->routing)->setLinkOptions(array('class' => 'link large'));
                 } else {
                     //Set class "active" if the item is a link to the current page
                     $menu->addChild($item->text, $item->routing)->setLinkOptions(array('class' => 'link'));
                 }
             }
         }
     }
     return $menu;
 }