【问题标题】:In YII2, how can I show some notifications counter in the lable在 YII2 中,如何在标签中显示一些通知计数器
【发布时间】:2015-07-04 19:32:17
【问题描述】:

假设我有一个像这样的标签:
['label' => 'Notifications','url'=>['notifications/index']],
我用来显示导航菜单。
现在如何在菜单旁边显示一些通知计数器(如徽章)?

我在按钮中使用了它:

echo"<button id='new_data' name='New data' class='btn btn-default'>New Data<sup><font color='red' size='4'><b>".$new_data_number."</b></font></sup></button>";

其中 $new_data_number 是要在通知中显示的数字。现在我想在菜单中显示数字。

由于无法发表任何评论,我编辑了问题。这是我的代码:

在组件/MenueHelper.php 文件中:

public static function getLowermenu()
  {
    $role_name = \Yii::$app->session->get('usertypename');
    $result    = static::getLowerRecrusive($role_name);
    return $result;
  }

private static function getLowerRecrusive($parent)
  {
    $result = [];
    $counter = 10;
    if($parent == 'Admin')
    {
      $result =
      [
        ['label' => 'Users', 'url' => ['users/index']],
        ['label' => '<span class="pull-right badge">10</span> New Arrivals', 'icon' => 'home'],
      ];
      return $result

现在在布局文件中:
<?php echo Nav::widget([ 'options' => ['class' => 'right'], 'items' => app\components\MenuHelper::getLowermenu(), ]); ?>

第一个标签(Users)没问题,但对于第二个标签(New Arrival),它也显示 html 代码。
提前致谢。

【问题讨论】:

    标签: menu notifications label yii2 nav


    【解决方案1】:

    试试

    ['label' => 'Notifications' .$new_data_number,'url'=>['notifications/index']],
    

    第二个问题试试

    ['label' =>  '<span class="badge">'.$new_data_number .'</span>'
    

    【讨论】:

    • 实际上它部分解决了我的问题,现在它在链接旁边显示 $new_data_number,但我需要一些像引导程序中的 badge 一样的想法:&lt;span class="badge"&gt;$new_data_number&lt;/span&gt;
    • 我已经更新了答案。基本上,您必须动态组合字符串以与标签关联
    • 对不起,它没有显示通知的东西,它显示了整个 html 代码。感谢您的回复。
    • 检查 ' 和 " 字符序列或发布所有实际菜单代码。
    猜你喜欢
    • 2017-05-22
    • 1970-01-01
    • 2013-07-08
    • 2016-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-09
    相关资源
    最近更新 更多