Hassan Jamal
Hassan Jamal

Reputation: 694

Drop Down menu with yii framework and twitter bootstrap

How to achieve drop down menu with yii framework using CMenu and twitter Bootstrap . Without drop down i am able to accomplish task but drop down i am stuck ?

http://yiistrap.blogspot.in/2013/07/yii-framework-with-twitter-bootstrap-in.html

Upvotes: 0

Views: 4731

Answers (2)

Hearaman
Hearaman

Reputation: 8726

This is basic Syntax http://www.cniska.net/yii-bootstrap/

        <div class="btn-toolbar">
            <?php
            $this->widget('bootstrap.widgets.TbButtonGroup', array(
                'type' => 'primary',
                'buttons' => array(
                    array('label' => 'Action', 'items' => array(
                            array('label' => 'Action', 'url' => '#'),
                            array('label' => 'Another action', 'url' => '#'),
                            array('label' => 'Something else', 'url' => '#'),
                            array('label' => 'Separate link', 'url' => '#'),
                    )),
                ),
            ));
            ?>
        </div>

I have a user table (Model name is TblUser) as bellow

        ----------------
        id      username
        ----------------
        1       Hearaman
        2       Dileep
        3       Rakesh
        -----------------

Ex:

I want to show User list in drop down, When you choose link it has to go to respective user profile

        <?php
        $usersAry = CHtml::listData(TblUser::model()->findAll(array('order' => 'id')), 'id', 'username');

        //$usersAry comes with id as key and username as value
        //echo "<pre>";
        //print_r($usersAry);
        //echo "</pre>";

        $items=array();
        foreach ($usersAry as $userId=>$user)
        {
            $items[]=array('label'=>$user,'url'=>'/user/view/'.$userId);
        }
        ?>

        <div class="btn-toolbar">
            <?php
            $this->widget('bootstrap.widgets.TbButtonGroup', array(
                'type' => 'primary',
                'buttons' => array(
                    array('label' => 'User List', 'items' => $items),
                ),
            ));
            ?>
        </div>

Upvotes: 1

Bharu
Bharu

Reputation: 191

you can also use button dropdown menu in bootstrap

   $this->widget('bootstrap.widgets.TbButtonGroup', array(
  'type' => 'primary', // '', 'primary', 'info', 'success', 'warning', 'danger' or 'inverse'
    'buttons' => array(
                    array('label' => 'Action', 'url' => '#'), // this makes it split :)
                    array('items' => array(
                    array('label' => 'Action', 'url' => '#'),
                    array('label' => 'Another action', 'url' => '#'),
                    array('label' => 'Something else', 'url' => '#'),
                    array('label' => 'Separate link', 'url' => '#'),
    )),
    ),

));

or in Navbar menu you can add sub menu like this..

   array('label'=>'First Link', 'url'=>"#", 'itemOptions'=>array('id' => 'xyz'))

Upvotes: 0

Related Questions