Yii2 yii基本应用程序,当使用导航条开始时,yii细枝类设置为0类
我使用yii作为一个基本的应用程序,扩展了yii twig,并使用nav_bar_begin创建了一个导航菜单,但是这个类的设置与我预期的不同,因为这个导航菜单是灰色的,而不是黑色的 当我查看源代码时,我看到:Yii2 yii基本应用程序,当使用导航条开始时,yii细枝类设置为0类,yii2,twig,yii-extensions,yii2-basic-app,twig-extension,Yii2,Twig,Yii Extensions,Yii2 Basic App,Twig Extension,我使用yii作为一个基本的应用程序,扩展了yii twig,并使用nav_bar_begin创建了一个导航菜单,但是这个类的设置与我预期的不同,因为这个导航菜单是灰色的,而不是黑色的 当我查看源代码时,我看到: <nav id="w0" class="navbar navbar-default" 0-class="navbar-inverse navbar-fixed-top"> <div class="container"><div class="navb
<nav id="w0" class="navbar navbar-default" 0-class="navbar-inverse navbar-fixed-top">
<div class="container"><div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#w0-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">My Application</a>
</div>
<div id="w0-collapse" class="collapse navbar-collapse">
<ul id="w1" class="navbar-nav navbar-right nav">
<li class="active"><a href="/">Home</a></li>
<li><a href="/about">About</a></li>
<li><a href="/contact">Contact</a></li>
<li><a href="/login">login</a></li>
</ul>
</div>
</div>
这也是关于如何设置yii和twig的config/web.php文件
$params = require __DIR__ . '/params.php';
$db = require __DIR__ . '/db.php';
$config = [
'id' => 'basic',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'aliases' => [
'@bower' => '@vendor/bower-asset',
'@npm' => '@vendor/npm-asset',
],
'components' => [
'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => 'ywLqCkq0cMC-cvfVXiGXFnfu2S41_CbC',
],
'cache' => [
'class' => 'yii\caching\FileCache',
],
'user' => [
'identityClass' => 'app\models\User',
'enableAutoLogin' => true,
],
'errorHandler' => [
'errorAction' => 'site/error',
],
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => true,
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'db' => $db,
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'enableStrictParsing' => true,
//'class' => 'yii\web\UrlManager',
'baseUrl' => '/',
'rules' => [
'/' => 'site/index',
'about' => 'site/about',
'contact' => 'site/contact',
'login' => 'site/login',
],
],
/*
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
],
],
*/
// setting up twig
'view' => [
'class' => 'yii\web\View',
'renderers' => [
'twig' => [
'class' => 'yii\twig\ViewRenderer',
'cachePath' => false, // '@runtime/Twig/cache',
// Array of twig options:
'options' => [
'auto_reload' => true,
YII_DEBUG ? [ 'debug' => true, ] : [],
],
'extensions' => YII_DEBUG ? [ '\Twig_Extension_Debug', ] : [],
'globals' => [
'html' => '\yii\helpers\Html',
'url' => '\yii\helpers\Url',
'yii' => 'Yii',
],
'uses' => ['yii\bootstrap'],
],
],
],
],
'layout' => 'main.twig',
'params' => $params,
];
if (YII_ENV_DEV) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [
'class' => 'yii\debug\Module',
// uncomment the following to add your IP if you are not connecting from localhost.
'allowedIPs' => ['127.0.0.1', '::1', '192.168.0.*'],
];
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
// uncomment the following to add your IP if you are not connecting from localhost.
'allowedIPs' => ['127.0.0.1', '::1', '192.168.0.*'],
];
}
return $config;
小部件配置中有错误。替换
'options': [{
'class': 'navbar-inverse navbar-fixed-top',
}],
与
啊!非常感谢您指出这一点,我已经尝试解决了一段时间,但看不出问题是什么。回顾一下我的代码,我在第一篇文章中做的是错误的,然后按照您在下面的选项中提到的那样正确地做了。从那以后,我把它们都做成了和你提到的一样的东西,解决了这个问题,再次感谢你@AeroMaxx如果属性中有一些
0-*=”
或0=“
,通常意味着有一些嵌套数组或忘记为值指定键。
'options': [{
'class': 'navbar-inverse navbar-fixed-top',
}],
'options': {
'class': 'navbar-inverse navbar-fixed-top',
},