2013-07-22 19 views
1

我正在將Yii Framework和Yii Booster擴展作爲引導。我正在嘗試在下拉列表中創建一個登錄表單。我有一個TbNavbar,並且它是下拉代碼,但是當我在下拉列表中添加登錄表單時,它只是顯示下拉內的代碼。TbNavbar內部下拉項目的形式YiiBooster

我爲先導用這個貼子:

這裏是我的代碼的形式和它只是不工作:

<?php $this->beginWidget('bootstrap.widgets.TbNavbar', array(
'type'=>'inverse', 
'brand' => 'Title', 
'fixed'=>'bottom', 
'collapse'=>true, 
'items'=>array(
array(
    'class'=>'bootstrap.widgets.TbMenu', 
    'type'=>'inverse', 
    'items'=>array(
    array('label'=>'Home', 'url'=>'#', 'active'=>true), 
    array('label'=>'Link', 'url'=>'#'), 
    array('label' => 'DropDown', 'items' => array(
      array('label' => 'Item1', 'content' => 'Item1 Content'), 
      array('label' => 'Item2', 'content' => 'Item2 Content') 
     )), 
    array('label'=>'Dropdown', 'url'=>'#', 'items'=>array(
     array('label'=>'Action', 'url'=>'#'), 
     array('label'=>'Another action', 'url'=>'#'), 
     array('label'=>'Something else here', 'url'=>'#'), 
     '---', 
     array('label'=>'NAV HEADER'), 
     array('label'=>'Separated link', 'url'=>'#'), 
     array('label'=>'One more separated link', 'url'=>'#'), 


    )), 
), 
), 


'<ul class="nav pull-right"> 
       <li><a href="https://stackoverflow.com/users/sign_up">Sign Up</a></li> 
       <li class="divider-vertical"></li> 
       <li class="dropdown"> 
        <a class="dropdown-toggle" href="#" data-toggle="dropdown">Sign In <strong class="caret"></strong></a> 
        <div class="dropdown-menu" style="padding: 15px; padding-bottom: 0px;"> 
         <?php $form = $this->beginWidget(\'bootstrap.widgets.TbActiveForm\', array(
          \'id\'=>\'verticalForm\', 
          \'htmlOptions\'=>array(\'class\'=>\'well\'), 
        )); ?> 

         <?php echo $form->textFieldRow($model, \'textField\', array(\'class\'=>\'span3\')); ?> 
         <?php echo $form->passwordFieldRow($model, \'password\', array(\'class\'=>\'span3\')); ?> 
         <?php echo $form->checkboxRow($model, \'checkbox\'); ?> 
         <?php $this->widget(\'bootstrap.widgets.TbButton\', array(\'buttonType\'=>\'submit\', \'label\'=>\'Login\')); ?> 

         <?php $this->endWidget(); ?> 
        </div> 
       </li> 
      </ul>' ),)); ?> 
<?php $this->endWidget(); ?> 

回答

0

嘗試這樣的。這是爲我工作

 <?php 
     $this->beginWidget('bootstrap.widgets.TbNavbar', array(
      'type' => 'inverse', 
      'brand' => 'Title', 
      'fixed' => 'bottom', 
      'collapse' => true, 
      'items' => array(
       array(
        'class' => 'bootstrap.widgets.TbMenu', 
        'type' => 'inverse', 
        'items' => array(
         array('label' => 'Home', 'url' => '#', 'active' => true), 
         array('label' => 'Link', 'url' => '#'), 
         array('label' => 'DropDown', 'items' => array(
           array('label' => 'Item1', 'content' => 'Item1 Content'), 
           array('label' => 'Item2', 'content' => 'Item2 Content') 
         )), 
         array('label' => 'Dropdown', 'url' => '#', 'items' => array(
           array('label' => 'Action', 'url' => '#'), 
           array('label' => 'Another action', 'url' => '#'), 
           array('label' => 'Something else here', 'url' => '#'), 
           '---', 
           array('label' => 'NAV HEADER'), 
           array('label' => 'Separated link', 'url' => '#'), 
           array('label' => 'One more separated link', 'url' => '#'), 
         )), 
        ), 
       ), 
       '<ul class="nav pull-right"> 
      <li><a href="https://stackoverflow.com/users/sign_up">Sign Up</a></li> 
      <li class="divider-vertical"></li> 
      <li class="dropdown"> 
       <a class="dropdown-toggle" href="#" data-toggle="dropdown">Sign In <strong class="caret"></strong></a> 
       <div class="dropdown-menu" style="padding: 15px; padding-bottom: 0px;">' . html($this,$model) . '</div> 
      </li> 
     </ul>'), 
       ) 
     ); 
     ?> 
     <?php $this->endWidget(); ?> 

函數定義

<?php 
    function html($obj,$model) 
    { 
     $html=''; 
     $form = $obj->beginWidget('bootstrap.widgets.TbActiveForm', array(
      'id' => 'verticalForm', 
      'htmlOptions' => array('class' => 'well') 
       )); 
     $html.=$form->textFieldRow($model, 'textField', array('class' => 'span3')); 
     $html.=$form->passwordFieldRow($model, 'password', array('class' => 'span3')); 
     $html.=$form->checkboxRow($model, 'checkbox'); 
     $html.=CHtml::submitButton('Login',array('class'=>'btn btn-info'));  
     $obj->endWidget(); 

     return $html; 
    } 
    ?> 

編輯 ::按照波紋管評論

你可以當你在室內工作停止引導下拉的默認傳播下拉內容。

 <script type="text/javascript"> 
      $(document).ready(function() 
      {   
       $('.dropdown-menu').click(function(e) 
       {    
        e.stopPropagation();    
       }); 
      }); 
     </script> 
+0

謝謝!這是現在的下拉,但是當我點擊該按鈕,沒做什麼:C 附加到我有一些代碼停在thextfields和「登錄按鈕」 ptopagation,因爲當你在的東西點擊它下拉沒有理由隱藏。這可能是一個問題嗎? –

+0

@AareelyCoca,請檢查編輯以解決您在下拉菜單時遇到的問題。 – Hearaman

+0

好吧,我把所有的代碼,你把我在這裏,當我點擊它讓無所事事的按鈕:C也會是別的我失蹤? –

0

把這段代碼放到你的主佈局頭部。這將加載JavaScript,菜單應該與它一起工作。

<?php Yii::app()->bootstrap->registerAssetJs('');?>