I just started with the Yii framework using the bootstrap theme; everything is awesome, except that I can't find a way of naming attributes in bootstrap widgets. For instance site has a chat button, how do i access it by jQuery('#id')?

I tried adding in the id attribute of the same array as follows:

<?php $this->widget('bootstrap.widgets.TbButton',array(
    'buttonType'=>'link',
    'icon' => 'icon-user icon-white',
    'type'=>'info',
    'label'=>'Live chat',
    'url'=>'javascript:switchChat();',
    'id'=>'chatPopup'
    )); ?>

Ok, after little head scratching i found out about htmlOptions array and itemOptions :)

Ok finally got there

        'class'=>'bootstrap.widgets.TbMenu',
        'items'=>array(
            array('label'=>'Home', 'url'=>array('/site/index')),
            array('label'=>'Messages ()',
                  'url'=>array('/site/messages'),
                  'visible'=>!Yii::app()->user->isGuest,
                  'itemOptions'=>array('class'=>'msgcnt'),
            ),

But this doesn't generate attributes for me, except the standard url, type, etc.

So the only way I am currently able to do this is by placing widgets within div wrappers with ids, but how would I deal with those widgets where div is unacceptable, for example in the case of a navbar?

有帮助吗?

解决方案

You can set attributes through the htmlOptions property:

<?php $this->widget('bootstrap.widgets.TbButton',array(
    // ..
    'htmlOptions' => array(
        'id' => 'myid',
    ),
));?>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top