อยากสอบถาม เราจะกำหนดยังไงให้เมนูที่เรากำหนดแสดงต่อเมือ login เท่านั้นครับ

wave
final888
1,659
สังคมนักพัฒนาระบบ (Community)
อยากสอบถาม เราจะกำหนดยังไงให้เมนูที่เรากำหนดแสดงต่อเมือ login เท่านั้นครับ

'options' => ['class' => 'sidebar-menu tree', 'data-widget'=> 'tree'],
                'items' => [
                    ['label' => 'Menu Yii2  '. Yii::$app->user->identity->username.' ', 'options' => ['class' => 'header']],
                    ['label' => 'Gii', 'icon' => 'file-code-o', 'url' => ['/gii']],
                    ['label' => 'Debug', 'icon' => 'dashboard', 'url' => ['/debug']],
                    ['label' => 'Login', 'url' => ['site/login'], 'visible' => Yii::$app->user->isGuest],
                    ['label' => 'signup', 'url' => ['site/signup'], 'visible' => Yii::$app->user->isGuest],
                    
     

 

2 ความคิดเห็น

  • final888

  • มานพ กองอุ่น

ตัวอย่าง

<?php
    NavBar::begin([
        'brandLabel' => false,//Html::img($asset . '/images/logo/logo3_' . Yii::$app->language . '.png', ['class' => 'img-responsive', 'alt' => Yii::t('frontend', 'Institute of Pathology')]),
        'brandUrl' => Yii::$app->homeUrl,
        'renderInnerContainer' => false,
        'options' => [
            'class' => 'navbar-default',
        ],
    ]);
    $menuItems = [
        ['label' => '<span class="glyphicon glyphicon-home"></span><br />หน้าหลัก', 'url' => ['/site/index']],
        ['label' => '<span class="glyphicon glyphicon-book"></span><br />ข่าวประชาสัมพันธ์', 'url' => ['/site/news']],
        ['label' => '<span class="glyphicon glyphicon-comment"></span><br />กระดานข่าว', 'url' => ['/site/webboard']],
        ['label' => '<span class="glyphicon glyphicon-book"></span><br />ฐานข้อมูลเครือข่ายด้านพยาธิฯ', 'url' => ['/report/index']],
        ['label' => '<span class="glyphicon glyphicon-folder-open"></span><br />รายงานการประชุม', 'url' => ['/site/minute-report']],
        ['label' => '<span class="glyphicon glyphicon-cog"></span><br />เกี่ยวกับ', 'url' => '#', 'items' => [
            ['label' => '<span class="glyphicon glyphicon-envelope"></span> เกี่ยวกับระบบ', 'url' => ['/site/about']],
            ['label' => '<span class="glyphicon glyphicon-envelope"></span> ติดต่อ', 'url' => ['/site/contact']],
        ]],
        
    ];
    if (Yii::$app->user->isGuest) {
        //$menuItems[] = ['label' => 'Signup', 'url' => ['/site/signup']];
        $menuItems[] = ['label' => '<span class="glyphicon glyphicon-user"></span><br />เข้าสู่ระบบ', 'url' => ['/site/login']];
    } else {
        $menuItems[] = ['label' => '<span class="glyphicon glyphicon-heart"></span><br />'.(isset(Yii::$app->user->identity->profile->department) ? Yii::$app->user->identity->profile->department->name : Yii::$app->user->identity->profile->name).' ('.Yii::$app->user->identity->username.')', 'url' => '#',
        'items' => [
            ['label' => '<span class="glyphicon glyphicon-th-large"></span> แผงควบคุม', 'url' => ['/patho/default/index']],
            ['label' => '<span class="glyphicon glyphicon-user"></span> ข้อมูลบุคลากรงานพยาธิวิทยา', 'url' => ['/patho/person/index']],
            ['label' => '<span class="glyphicon glyphicon-wrench"></span> ข้อมูลเครื่องมืออุปกรณ์', 'url' => ['/patho/tool/index']],
            ['label' => '<span class="glyphicon glyphicon-list-alt"></span> ข้อมูลชนิดการส่งตรวจ', 'url' => ['/patho/service/index']],
            ['label' => '<span class="glyphicon glyphicon-folder-open"></span> รายงานการประชุมทางพยาธิ', 'url' => ['/patho/minute-report/index']],
            ['label' => '<span class="glyphicon glyphicon-bullhorn"></span> แจ้งข่าวสาร', 'url' => ['/patho/news/index']],
            ['label' => '<span class="glyphicon glyphicon-comment"></span> กระดานข่าว', 'url' => ['/patho/webboard/index']],
            ['label' => '<span class="glyphicon glyphicon-heart"></span> ข้อมูลหน่วยงาน', 'url' => ['/patho/department/index']],
            ['label' => '<span class="glyphicon glyphicon-user"></span> ข้อมูลผู้ใช้งาน (' . Yii::$app->user->identity->username . ')', 'url' => ['/patho/user/index']],
            '<li>'
            . Html::beginForm(['/site/logout'], 'post')
            . Html::submitButton(
                '<span class="glyphicon glyphicon-share"></span> ออกจากระบบ (' . Yii::$app->user->identity->username . ')',
                ['class' => 'btn btn-link logout']
            )
            . Html::endForm()
            . '</li>'
        ]
    ];
       
        
    }

    echo Nav::widget([
        'options' => [
            'class' => 'navbar-nav navbar-center',
        ],
        //'dropDownCaret' => '<i class="fa fa-angle-right" aria-hidden="true"></i>',
        'encodeLabels' => false,
        'items' => $menuItems,
    ]);
    NavBar::end();
    ?>

 

ขอบคุณมากครับ เดี๋ยวขอทดสอบก่อนครับ เดี๋ยวติดปัญหาเดี๋ยวมาขอความช่วยเหลือใหม่ครับ