小 body 使用自定义模板 yii2
small body using custom template yii2
我正在尝试在 yii2 基本应用程序中使用 Architect 免费模板。
我在使用标签时遇到问题
<?php $this->beginBody() ?> and <?php $this->endBody() ?>
这使得 body 内容非常小,正如您在这张图片上看到的那样:
如果我不使用标签,它看起来像这样:
如果我不使用标签,Javascript 事件(如验证)将无法正常工作。
在这种情况下我能做什么?
Main.php
代码:
<?php
use app\assets\AppAsset;
use yii\helpers\Html;
use yii\web\YiiAsset;
use app\widgets\Alert;
AppAsset::register($this);
?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta charset="<?= Yii::$app->charset ?>">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, shrink-to-fit=no" />
<meta name="msapplication-tap-highlight" content="no">
<?php $this->registerCsrfMetaTags() ?>
<title><?= Yii::$app->name ?> - <?= Html::encode($this->title) ?></title>
<?php $this->head() ?>
</head>
<body>
<?= $this->render('cabecera') ?>
<?= $this->render('menu') ?>
<div class="app-main__outer">
<div class="app-main__inner">
<div class="app-page-title">
<div class="page-title-wrapper">
<?= Alert::widget() ?>
<?= $content ?>
</div>
</div>
</div>
<?= $this->render('footer') ?>
</div>
</body>
</html>
<?php $this->endPage() ?>
更新:
我检查了 AppAsset.php 文件,我注意到如果我注释“yii\bootstrap\BootstrapAsset”这一行,body 页面会恢复正常但没有任何 bootstrap 样式。
AppAsset.php:
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace app\assets;
use yii\web\AssetBundle;
/**
* Main application asset bundle.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class AppAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
// 'css/site.css',
'css/main.css',
];
public $js = [
'js/main.js',
];
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapAsset', //I have the issue with this one
'yii\web\JqueryAsset',
];
// public $jsOptions = array(
// 'position' => \yii\web\View::POS_HEAD
// );
}
抱歉,打扰了,我发现它失败的原因,正如@ustmaestro 所说,yii2 有不同的 bootstrap 版本,模板使用 bootstrap4.
安装 yii2 bootstrap4 包后,它完美运行。
必须更改代码以插入 bootstrap4 个函数。
你好。
我正在尝试在 yii2 基本应用程序中使用 Architect 免费模板。
我在使用标签时遇到问题
<?php $this->beginBody() ?> and <?php $this->endBody() ?>
这使得 body 内容非常小,正如您在这张图片上看到的那样:
如果我不使用标签,它看起来像这样:
如果我不使用标签,Javascript 事件(如验证)将无法正常工作。
在这种情况下我能做什么?
Main.php
代码:
<?php
use app\assets\AppAsset;
use yii\helpers\Html;
use yii\web\YiiAsset;
use app\widgets\Alert;
AppAsset::register($this);
?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta charset="<?= Yii::$app->charset ?>">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, shrink-to-fit=no" />
<meta name="msapplication-tap-highlight" content="no">
<?php $this->registerCsrfMetaTags() ?>
<title><?= Yii::$app->name ?> - <?= Html::encode($this->title) ?></title>
<?php $this->head() ?>
</head>
<body>
<?= $this->render('cabecera') ?>
<?= $this->render('menu') ?>
<div class="app-main__outer">
<div class="app-main__inner">
<div class="app-page-title">
<div class="page-title-wrapper">
<?= Alert::widget() ?>
<?= $content ?>
</div>
</div>
</div>
<?= $this->render('footer') ?>
</div>
</body>
</html>
<?php $this->endPage() ?>
更新:
我检查了 AppAsset.php 文件,我注意到如果我注释“yii\bootstrap\BootstrapAsset”这一行,body 页面会恢复正常但没有任何 bootstrap 样式。
AppAsset.php:
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace app\assets;
use yii\web\AssetBundle;
/**
* Main application asset bundle.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class AppAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
// 'css/site.css',
'css/main.css',
];
public $js = [
'js/main.js',
];
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapAsset', //I have the issue with this one
'yii\web\JqueryAsset',
];
// public $jsOptions = array(
// 'position' => \yii\web\View::POS_HEAD
// );
}
抱歉,打扰了,我发现它失败的原因,正如@ustmaestro 所说,yii2 有不同的 bootstrap 版本,模板使用 bootstrap4.
安装 yii2 bootstrap4 包后,它完美运行。
必须更改代码以插入 bootstrap4 个函数。
你好。