2016-12-17 4 views
1

URL의 컨트롤러/동작을 설정하여 Kartik의 SideNav (http://demos.krajee.com/sidenav-demo/profile/default)가 제대로 작동하지만 메뉴가 열린 상태로 유지되도록 활성 옵션을 설정하는 방법을 이해하지 못합니다. 올바른 메뉴 항목이 선택된 상태로 유지됩니다.Yii2 Kartik SideNav '활성'옵션을 설정하는 방법

'활성'=> '컨트롤러/동작/기본 # 데모'뿐 아니라 '활성'=> '컨트롤러/동작'(아래 참조) 설정을 시도했지만 아무 소용이 없습니다. 'employee/employee-dashboard/default # demo'로 설정하면 하나의 탭이 강조 표시되지만 해당 탭에서 동일한 방식으로 다른 탭을 변경하지는 않습니다. 원본은 '활성'=> '집'으로 설정되었지만 그저 행동 일뿐입니다. 그러나 그것은 저에게도 효과가 없었습니다.

  $type = SideNav::TYPE_DEFAULT; 
      $heading = '<i class="glyphicon glyphicon-cog"></i> Employee Menu'; 
      $item = '/employee/employee-dashboard/default#demo'; 

echo SideNav::widget([ 
       'type' => $type, 
       'encodeLabels' => false, 
       'heading' => $heading, 
       'items' => [ 
        // Important: you need to specify url as 'controller/action', 
        // not just as 'controller' even if default action is used. 
        // 
        // NOTE: The variable `$item` is specific to this demo page that determines 
        // which menu item will be activated. You need to accordingly define and pass 
        // such variables to your view object to handle such logic in your application 
        // (to determine the active status). 
        // 
        ['label' => 'Dashboard', 'icon' => 'home', 'url' => Url::to(['/employee/employee-dashboard', 'type'=>$type]), 'active' => ($item == '/employee/employee-dashboard/default#demo')] 

        ['label' => 'Paycheck Info', 'icon' => 'book', 'items' => [ 
         ['label' => '<span class="pull-right badge">10</span> W2 Forms', 'url' => Url::to(['/employee/w2-form', 'type'=>$type]), 'active' => ($item == 'w2-form')], 
+0

그냥 설명을 원합니다. 메뉴 행 (드롭 다운)을'active'로 설정하고 모든 자식과 함께 열어 두어야합니까? –

+0

예. 제대로 작동하려면 데모 페이지 (http://demos.krajee.com/sidenav-demo/profile/default)를 참조하십시오. 현재 어떤 메뉴 항목을 클릭해도 올바른 페이지로 이동하지만 메뉴 항목은 강조 표시되지 않고 하위 항목이있는 확장 메뉴 인 경우 메뉴가 닫힙니다. 감사. – Marko

답변

1
'active'=>($item == 'about') 

where 
    $item = Yii::$app->controller->action->id; 


This is how i used 

<?php 

    $item = Yii::$app->controller->action->id; 
    echo SideNav::widget([ 
     'type' => SideNav::TYPE_DEFAULT, 
     'heading' => 'Options', 
     'items' => [ 
      [ 
       'url' => Yii::$app->homeUrl, 
       'label' => 'Home', 
       'icon' => 'home', 
       'active'=>($item == 'index') 
      ], 
      [ 
       'label' => 'Help', 
       'icon' => 'question-sign', 
       'items' => [ 
        ['label' => 'About', 'icon'=>'info-sign', 'url'=>Yii::$app->homeUrl.'site/about', 'active'=>($item == 'about')], 
        ['label' => 'Contact', 'icon'=>'phone', 'url'=>Yii::$app->homeUrl.'site/contact', 'active'=>($item == 'contact')], 
       ], 
      ], 
     ], 
    ]); 
?> 
+0

감사합니다. 이것은 많은 페이지의 레이아웃 파일에서 사용할 수있는 매우 우아한 솔루션입니다. 내가 찾은 다른 해결책 (단지 몇 분 전)은 아래에 게시 할 예정이며 개별 페이지에서 사용하도록 강요합니다. – Marko

0

하나의 해결책은 당신이 페이지 단위로 활성화 된 메뉴 항목을 설정하려면입니다 발견

단지 SideNav 위젯 (예 : sidemenu.php) 별도의 뷰 파일 만들기 'currentPage'라는 매개 변수를 허용합니다.

echo SideNav::widget([ 
    'type' => SideNav::TYPE_DEFAULT, 
    'heading' => 'Options', 
    'items' => [ 
     [ 
      'url' => Url::toRoute('/site/index'), 
      'label' => 'Home', 
      'icon' => 'file', 
      'active'=>($currentPage == 'home'), 
     ], 
     [ 
      'url' => Url::toRoute('/site/about'), 
      'label' => 'About', 
      'icon' => 'file', 
      'active'=>($currentPage == 'about'), 
     ], 

그런 다음 메뉴를 렌더링하는 뷰 페이지에서 currentPage 속성을 설정 - 예 :

echo $this->render('sidemenu', ['currentPage'=>'home']); 

또는 이 반향을 $ this-> ('sidemenu를'렌더링, [ ' currentPage '=>'about ']);