Phundament App Class Reference
  • Package
  • Class
  • Tree

Packages

  • bootstrap
    • widgets
      • input
  • Image
  • None
  • p3admin
  • p3extensions
    • behaviors
    • commands
    • components
    • helpers
    • widgets
  • p3media
    • actions
    • controllers
    • models
  • p3pages
    • models
  • p3widgets
    • components
    • models
  • PHP
  • system
    • db
      • ar
    • gii
    • web
      • auth
      • helpers
      • widgets
  • yiiext
    • widgets
      • fancybox
      • lipsum
  • zii
    • widgets
      • grid

Classes

  • TbActiveForm
  • TbAlert
  • TbBadge
  • TbBreadcrumbs
  • TbButton
  • TbButtonColumn
  • TbButtonGroup
  • TbCarousel
  • TbCollapse
  • TbDataColumn
  • TbDetailView
  • TbDropdown
  • TbGridView
  • TbHeroUnit
  • TbLabel
  • TbListView
  • TbMenu
  • TbModal
  • TbNavbar
  • TbPager
  • TbProgress
  • TbScrollSpy
  • TbTabs
  • TbThumbnails
  • TbTypeahead
  1 <?php
  2 /**
  3  * TbNavbar class file.
  4  * @author Christoffer Niska <ChristofferNiska@gmail.com>
  5  * @copyright Copyright &copy; Christoffer Niska 2011-
  6  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
  7  * @package bootstrap.widgets
  8  * @since 0.9.7
  9  */
 10 
 11 Yii::import('bootstrap.widgets.TbCollapse');
 12 
 13 /**
 14  * Bootstrap navigation bar widget.
 15  */
 16 class TbNavbar extends CWidget
 17 {
 18     // Navbar types.
 19     const TYPE_INVERSE = 'inverse';
 20 
 21     // Navbar fix locations.
 22     const FIXED_TOP = 'top';
 23     const FIXED_BOTTOM = 'bottom';
 24 
 25     /**
 26      * @var string the navbar type. Valid values are 'inverse'.
 27      * @since 1.0.0
 28      */
 29     public $type;
 30     /**
 31      * @var string the text for the brand.
 32      */
 33     public $brand;
 34     /**
 35      * @var string the URL for the brand link.
 36      */
 37     public $brandUrl;
 38     /**
 39      * @var array the HTML attributes for the brand link.
 40      */
 41     public $brandOptions = array();
 42     /**
 43      * @var mixed fix location of the navbar if applicable.
 44      * Valid values are 'top' and 'bottom'. Defaults to 'top'.
 45      * Setting the value to false will make the navbar static.
 46      * @since 0.9.8
 47      */
 48     public $fixed = self::FIXED_TOP;
 49     /**
 50     * @var boolean whether the nav span over the full width. Defaults to false.
 51     * @since 0.9.8
 52     */
 53     public $fluid = false;
 54     /**
 55      * @var boolean whether to enable collapsing on narrow screens. Default to false.
 56      */
 57     public $collapse = false;
 58     /**
 59      * @var array navigation items.
 60      * @since 0.9.8
 61      */
 62     public $items = array();
 63     /**
 64      * @var array the HTML attributes for the widget container.
 65      */
 66     public $htmlOptions = array();
 67 
 68     /**
 69      * Initializes the widget.
 70      */
 71     public function init()
 72     {
 73         if ($this->brand !== false)
 74         {
 75             if (!isset($this->brand))
 76                 $this->brand = CHtml::encode(Yii::app()->name);
 77 
 78             if (!isset($this->brandUrl))
 79                 $this->brandUrl = Yii::app()->homeUrl;
 80 
 81             $this->brandOptions['href'] = CHtml::normalizeUrl($this->brandUrl);
 82 
 83             if (isset($this->brandOptions['class']))
 84                 $this->brandOptions['class'] .= ' brand';
 85             else
 86                 $this->brandOptions['class'] = 'brand';
 87         }
 88 
 89         $classes = array('navbar');
 90 
 91         if (isset($this->type) && in_array($this->type, array(self::TYPE_INVERSE)))
 92             $classes[] = 'navbar-'.$this->type;
 93 
 94         if ($this->fixed !== false && in_array($this->fixed, array(self::FIXED_TOP, self::FIXED_BOTTOM)))
 95             $classes[] = 'navbar-fixed-'.$this->fixed;
 96 
 97         if (!empty($classes))
 98         {
 99             $classes = implode(' ', $classes);
100             if (isset($this->htmlOptions['class']))
101                 $this->htmlOptions['class'] .= ' '.$classes;
102             else
103                 $this->htmlOptions['class'] = $classes;
104         }
105     }
106 
107     /**
108      * Runs the widget.
109      */
110     public function run()
111     {
112         echo CHtml::openTag('div', $this->htmlOptions);
113         echo '<div class="navbar-inner"><div class="'.$this->getContainerCssClass().'">';
114 
115         $collapseId = TbCollapse::getNextContainerId();
116 
117         if ($this->collapse !== false)
118         {
119             echo '<a class="btn btn-navbar" data-toggle="collapse" data-target="#'.$collapseId.'">';
120             echo '<span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span>';
121             echo '</a>';
122         }
123 
124         if ($this->brand !== false)
125             echo CHtml::openTag('a', $this->brandOptions).$this->brand.'</a>';
126 
127         if ($this->collapse !== false)
128         {
129             $this->controller->beginWidget('bootstrap.widgets.TbCollapse', array(
130                 'id'=>$collapseId,
131                 'toggle'=>false, // navbars should be collapsed by default
132                 'htmlOptions'=>array('class'=>'nav-collapse'),
133             ));
134         }
135 
136         foreach ($this->items as $item)
137         {
138             if (is_string($item))
139                 echo $item;
140             else
141             {
142                 if (isset($item['class']))
143                 {
144                     $className = $item['class'];
145                     unset($item['class']);
146 
147                     $this->controller->widget($className, $item);
148                 }
149             }
150         }
151 
152         if ($this->collapse !== false)
153             $this->controller->endWidget();
154 
155         echo '</div></div></div>';
156     }
157 
158     /**
159      * Returns the navbar container CSS class.
160      * @return string the class
161      */
162     protected function getContainerCssClass()
163     {
164         return $this->fluid ? 'container-fluid' : 'container';
165     }
166 }
167 
Phundament App Class Reference API documentation generated by ApiGen 2.8.0