yii2 如何修改 布局模板 layout.php 的 $this->head()
网站配置
网站根目录
document_root=/home/xxx.com/basic/web
程序根目录
/home/xxx.com/basic
布局代码
php
<?php use yii\helpers\Html; use app\assets\AppAsset; AppAsset::register($this); ?> <!DOCTYPE html> <html lang="<?= Yii::$app->language ?>"> <head> <meta charset="<?= Yii::$app->charset ?>"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <?= Html::csrfMetaTags() ?> <title><?=Html::encode($this->title)?></title> <?php $this->head() ?> </head> <body> <?php $this->beginBody() ?> <?= $content ?> <!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> <script src="http://cdn.bootcss.com/jquery/1.11.2/jquery.min.js"></script> <!-- Include all compiled plugins (below), or include individual files as needed --> <script src="/public/bootstrap/js/bootstrap.min.js"></script> <?php $this->endBody() ?> </body> </html> <?php $this->endPage() ?>
如何把 如下这一段弄到
$this->head()
中
php
<!-- Bootstrap --> <link href="/public/bootstrap/css/bootstrap.min.css" rel="stylesheet"> <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> <!-- WARNING: Respond.js doesn't work if you view the page via file:// --> <!--[if lt IE 9]> <script src="http://cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script> <script src="http://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script> <![endif]-->
说明
/public
目录位于 /home/xx.com/basic/web/public
2015-2-10补充,方法是这样的
php
class Ie9Asset extends AssetBundle { public $basePath = '@webroot'; public $baseUrl = '@web'; public $css = []; public $jsOptions = [ 'condition' => 'It IE 9', ]; public $js = [ 'http://cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js', 'http://cdn.bootcss.com/respond.js/1.4.2/respond.min.js' ]; }
感谢
我叫红领巾
你的朋友奥布芮
11 years, 3 months ago