Reputation: 77
iam developing a online application using yii2 . i want to use a side bar menu in my application. how can i create ? i have only navigation bar menu. i want sidebar menu in right side.`
NavBar::begin([
'brandLabel' => 'Civil Department',
'brandUrl' => Yii::$app->homeUrl,
'options' => [
'class' => 'navbar-inverse navbar-fixed-top',
],
]);
echo Nav::widget([
'options' => ['class' => 'navbar-nav navbar-right'],
'items' => [
['label' => 'Home', 'url' => ['/site/index']],
['label' => 'About', 'url' => ['/site/about']],
['label' => 'Contact', 'url' => ['/site/contact']],
['label' => 'ApplicationsForms', 'url' => ['/site/index'],
'items' => [
['label' => 'Casual Leave', 'url' => ['casual-leaves/create']],
['label' => 'Mtech Leave', 'url' => ['mtech-leave/create']],
['label' => 'Phd Leave', 'url' => ['phd-leave/create']],
['label' => 'Duty Leave', 'url' => ['duty-leave/create']],
],'visible' => Yii::$app->user->isGuest // && Yii::$app->user->identity->level == Usertable::level1,
],
['label' => 'Leave Applications', 'url' => ['/site/index'],
'items' => [
['label' => 'Applications for casual leave', 'url' => ['casual-leaves/index']],
['label' => 'Applications for Mtech leave', 'url' => ['mtech-leave/index']],
['label' => 'Applications for Phd leave', 'url' => ['phd-leave/index']],
['label' => 'Applications for Duty leave', 'url' => ['duty-leave/index']],
],'visible' => !Yii::$app->user->isGuest // && Yii::$app->user->identity->level == Usertable::level1,
],
Yii::$app->user->isGuest ?
['label' => 'Login', 'url' => ['/site/login']] :
[
'label' => 'Logout (' . Yii::$app->user->identity->username . ')',
'url' => ['/site/logout'],
'linkOptions' => ['data-method' => 'post']
],
],
]);
NavBar::end();
?>
this is my navbar menu. what can i do for getting side bar menu. i want to re arrange the navbar. that is i try to put all the leave application in to sidebar .
composer.json
"name": "yiisoft/yii2-app-basic",
"description": "Yii 2 Basic Project Template",
"keywords": ["yii2", "framework", "basic", "project template"],
"homepage": "http://www.yiiframework.com/",
"type": "project",
"license": "BSD-3-Clause",
"support": {
"issues": "https://github.com/yiisoft/yii2/issues?state=open",
"forum": "http://www.yiiframework.com/forum/",
"wiki": "http://www.yiiframework.com/wiki/",
"irc": "irc://irc.freenode.net/yii",
"source": "https://github.com/yiisoft/yii2"
},
"minimum-stability": "stable",
"require": {
"php": ">=5.4.0",
"yiisoft/yii2": ">=2.0.5",
"yiisoft/yii2-bootstrap": "*",
"yiisoft/yii2-swiftmailer": "*",
"kartik-v/yii2-widgets": "dev-master"
},
"require-dev": {
"yiisoft/yii2-codeception": "*",
"yiisoft/yii2-debug": "*",
"yiisoft/yii2-gii": "*",
"yiisoft/yii2-faker": "*",
},
"config": {
"process-timeout": 1800
},
"scripts": {
"post-create-project-cmd": [
"yii\\composer\\Installer::postCreateProject"
]
},
"extra": {
"yii\\composer\\Installer::postCreateProject": {
"setPermission": [
{
"runtime": "0777",
"web/assets": "0777",
"yii": "0755"
}
],
"generateCookieValidationKey": [
"config/web.php"
]
},
"asset-installer-paths": {
"npm-asset-library": "vendor/npm",
"bower-asset-library": "vendor/bower"
}
}
}
is this correct i only add this line "kartik-v/yii2-widgets": "dev-master" any other process for installation
Upvotes: 3
Views: 9624
Reputation: 133410
THe simplest solution is use an extension like : http://demos.krajee.com/widget-details/sidenav
For a fixed sidenav you can define a proper layout or you can add you sidenav in you page .. like this sample
use yii\helpers\Url; // this is for Class URL ******
use kartik\widgets\SideNav;
$menuItems[] = ['label' => 'DFenX - Yii2 User - '. Yii::t('app','User Admin Panel'), 'icon' => 'cog', 'url'=>Url::to(['/user/admin/index'])];
$menuItems[] = ['label' => Yii::t('app','Authentication manager'), 'icon' => 'th-list', 'items' => [
['label' => 'Settings', 'icon' => 'th-list', 'items' => [
['label' => '/user/settings', 'url'=>Url::to(['/user/settings'])],
['label' => '/user/settings/profile', 'url'=>Url::to(['/user/settings/profile'])],
['label' => '/user/settings/account', 'url'=>Url::to(['user/settings/account'])],
['label' => '/user/settings/networks', 'url'=>Url::to(['/user/settings/networks'])],
]],
['label' => 'Registration', 'icon' => 'th-list', 'items' => [
['label' => '/user/registration/register', 'url'=>Url::to(['/user/registration/register'])],
['label' => '/user/registration/resend', 'url'=>Url::to(['/user/registration/resend'])],
]],
['label' => 'Security', 'icon' => 'th-list', 'items' => [
['label' => '/user/security/login', 'url'=>Url::to(['/user/security/login'])],
['label' => '/user/security/logout', 'url'=>Url::to(['/user/security/logout'])],
]],
['label' => 'Recovery', 'icon' => 'th-list', 'items' => [
['label' => '/user/recovery/request', 'url'=>Url::to(['/user/recovery/request'])],
['label' => '/user/recovery/reset', 'url'=>Url::to(['/user/recovery/reset'])],
]],
]];
$type = SideNav::TYPE_PRIMARY;
$heading = '<i class="glyphicon glyphicon-user"></i> ' . Yii::t('app','USER Admin - UTILITIES');
echo SideNav::widget([
'type' => $type,
'encodeLabels' => false,
'heading' => $heading,
'items' =>$menuItems,
]);
for installation see https://github.com/kartik-v/yii2-widgets or http://www.yiiframework.com/extension/yii2-widgets
Upvotes: 2