Php Yii:使用图像在导航栏中进行定位

Php Yii:使用图像在导航栏中进行定位,php,twitter-bootstrap,yii,localization,Php,Twitter Bootstrap,Yii,Localization,如果有一个带有多个标志的下拉菜单就好了。当我使用twitter引导时,有没有办法在导航中显示一个类似标志的图像? 如果选择一个标志,则语言和标志应更改 我可以显示支持引导的图标,但它们不包含任何标志 我希望有人能帮助我。下面是我的导航 $this->widget('bootstrap.widgets.TbNavbar', array( 'type' => 'null', // null or 'inverse' 'bra

如果有一个带有多个标志的下拉菜单就好了。当我使用twitter引导时,有没有办法在导航中显示一个类似标志的图像? 如果选择一个标志,则语言和标志应更改

我可以显示支持引导的图标,但它们不包含任何标志

我希望有人能帮助我。下面是我的导航

        $this->widget('bootstrap.widgets.TbNavbar', array(
            'type' => 'null', // null or 'inverse'
            'brand' => '<img src="http://localhost/images/logo.gif">',
            'brandUrl' => 'localhost',
            'collapse' => true, // requires bootstrap-responsive.css
            'items' => array(
                array(
                    'class' => 'bootstrap.widgets.TbMenu',
                    'type' => 'pills', // '', 'tabs', 'pills' (or 'list')
                    'items' => array(
                        array('label' => 'Home', 'url' => array('/site/index')),
                        array('label' => 'user create', 'url' => array('/account/user/create')),
                        array('label' => 'Contact', 'url' => array('/site/contact')),
                        array('label' => 'User', 'url' => array('/account/user/index')),
                    ),
                ),
                array(
                    'class' => 'bootstrap.widgets.TbMenu',
                    'type' => 'pills', // '', 'tabs', 'pills' (or 'list')
                    'htmlOptions' => array('class' => 'pull-right'),

                    'items' => array(

        /**Added to show, that here should appear the flag*/
                        array('label' => '','htmlOptions'=> array('src'=>'http://localhost/images/german.png'), 'url' => ''),

                        array('label' => 'Sign in', 'url' => array('/account/signup/login'), 'visible' => Yii::app()->user->isGuest),
                        array('label' => 'Sign up', 'url' => array('/account/signup/registration'), 'visible' => Yii::app()->user->isGuest),
                        array('label' => Yii::app()->user->name , 'url' => '#', 'items' => array(
                                array('label' => 'Action', 'url' => '#'),
                                array('label' => 'Another action', 'url' => '#'),
                                array('label' => 'Something else here', 'url' => '#'),
                                '---',
                                array('label' => 'Logout', 'url' => array('/account/signup/logout')),
                            ),'visible' => !Yii::app()->user->isGuest),
                        ),
                ),
            ),
        ));
$this->widget('bootstrap.widgets.TbNavbar',数组(
'type'=>'null',//null或'inverse'
“品牌”=>“,
'brandUrl'=>'localhost',
“collapse'=>true,//需要bootstrap-responsive.css
'items'=>数组(
排列(
'class'=>'bootstrap.widgets.TbMenu',
'type'=>'pills',/''tabs','pills'(或'list')
'items'=>数组(
数组('label'=>'Home','url'=>array('/site/index')),
数组('label'=>'user create','url'=>array('/account/user/create')),
数组('label'=>'Contact','url'=>数组('/site/Contact')),
数组('label'=>'User','url'=>array('/account/User/index')),
),
),
排列(
'class'=>'bootstrap.widgets.TbMenu',
'type'=>'pills',/''tabs','pills'(或'list')
'htmlOptions'=>array('class'=>'pull right'),
'items'=>数组(
/**添加以显示,此处应显示标志*/
数组('label'=>'','htmlOptions'=>数组('src'=>'http://localhost/images/german.png“),“url'=>”,
数组('label'=>'Sign-in','url'=>array('/account/signup/login'),'visible'=>Yii::app()->user->isGuest),
数组('label'=>'Sign-up','url'=>array('/account/signup/registration'),'visible'=>Yii::app()->user->isGuest),
数组('label'=>Yii::app()->user->name,'url'=>'#','items'=>array(
数组('label'=>'Action','url'=>'#'),
数组('label'=>'另一个操作','url'=>'#'),
数组('label'=>'Something here','url'=>'#'),
'---',
数组('label'=>'Logout','url'=>array('/account/signup/Logout')),
),“可见”=>!Yii::app()->user->isGuest),
),
),
),
));

正如您所注意到的,首先需要标志图标。例如,您可以使用。您可能需要或不需要稍微修改返回的CSS以满足您的需要

接下来,您需要创建交换机URL。这本质上归结为将当前URL和语言选择作为get参数。为您当前所在的站点创建规范链接,并附加
?lang=
。另一种方法是简单地将开关部分附加到当前URL并使用它。我概述了类似的情况

接下来,您需要确保您的应用程序能够实际处理本地化。我还不知道你在那条路上走了多远,所以你可能想看看。要真正打开请求,您可以在
protected/components/Controller.php

public function init() {
  parent:init();

  if (null === Yii::app()->user->getState('lang') || null !== Yii::app()->request->getQuery('lang', null)) {
        Yii::app()->user->setState('lang', Yii::app()->request->getQuery('lang','defaultLanguage'));
    }
    Yii::app()->setLanguage(Yii::app()->user->getState('lang'));

}
这样,无论您身在何处,该语言都会基于get参数进行设置,并在会话存在时保持不变。您甚至可能希望将“defaultLanguage”替换为对确定默认值的函数的调用,例如,基于浏览器的用户代理字符串或访问者的IP

要生成您需要/想要的语言文件,请查看


要在菜单内创建必要的链接,您可以创建一个返回相应数组的函数,或者使用三元运算符切换值,例如
'label'=>('en'==Yii::app()->language)“切换到西班牙语“:“切换到英语”
。然而,这只适用于二进制决策。如果你想提供更多的语言,你应该考虑一种不同的方法,比如我提到的函数。谢谢。我刚刚把你的建议添加到我的代码中,它真的很好用。但是CSS Spirits可以免费用于商业用途吗?正如我链接的网站上所描述的,这些Spirits“可以免费用于任何目的,不需要属性”。右侧的侧栏中提供了完整的许可证信息。