示例#1
0
 public function addSubmitAction()
 {
     $entity = $this->entity;
     $item = $entity::createNew();
     $postData = $_POST;
     $this->beforePageSave($item, $postData);
     // set nav position
     $largestPosition = 0;
     $existingPages = \Fierce\Page::all();
     foreach ($existingPages as $existingPage) {
         if (@$existingPage->nav != $postData['nav']) {
             continue;
         }
         if ($existingPage->navPositionRight > $largestPosition) {
             $largestPosition = $existingPage->navPositionRight;
         }
     }
     $postData['navPositionLeft'] = $largestPosition + 1;
     $postData['navPositionRight'] = $largestPosition + 2;
     $postData['navPositionDepth'] = 0;
     $item->setData($postData);
     $item->save();
     $this->afterSave($item);
     HTTP::redirect($this->url('edit', ['id' => $item->id]));
 }
示例#2
0
文件: NavNode.php 项目: fierce/fierce
 public static function printNav($identifier = 'main')
 {
     // fetch all pages, sorted by position
     $pages = \Fierce\Page::all('navPositionLeft');
     print '<ul class="nav">';
     $depth = 0;
     $first = true;
     foreach ($pages as $navPage) {
         // is this page in the nav?
         if (@$navPage->nav != $identifier) {
             continue;
         }
         // no change to depth? close the list item we left open in the last iteration.
         if (!$first && $navPage->navPositionDepth == $depth) {
             print '</li>';
         }
         // increase depth?
         while ($navPage->navPositionDepth > $depth) {
             print '<ul>';
             $depth++;
         }
         // reduce depth?
         if ($navPage->navPositionDepth < $depth) {
             while ($navPage->navPositionDepth < $depth) {
                 print '</li></ul>';
                 $depth--;
             }
             print '</li>';
         }
         // generate a nav item, leaving the list item open.
         $href = ltrim($navPage->url, '/');
         if ($href == '') {
             $href = './';
         }
         $href = htmlspecialchars($href);
         $name = htmlspecialchars($navPage->name);
         $isCurrent = \Fierce\Env::get('request_url') == $navPage->url;
         $classHtml = $isCurrent ? ' class="current"' : '';
         print '<li' . $classHtml . '><a href="' . $href . '">' . $name . '</a>';
         $first = false;
     }
     // close off open tags
     while ($depth >= 0) {
         print '</li></ul>';
         $depth--;
     }
 }