php - yii2 中的 Css 和 bootstrap

标签 php html css yii2

我是 Yii2 的新手,我已经创建了一个布局页面,但我的 CSS 不能完全发挥作用。它只加载它的一部分。有人可以帮帮我吗?

我的布局:

<?php
namespace app\views\layouts;

use yii\bootstrap\Alert;
use yii\bootstrap\ActiveForm;
use yii\helpers\Url;
use yii\helpers\Html;
use yii\bootstrap\NavBar;
use yii\bootstrap\Button;
use app\models\Search;
use yii\bootstrap\Nav;
use app\assets\AppAsset;
use app\models\LoginForm;
use yii\web\View;
use Yii;

AppAsset::register($this);
?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="language" content="en" />
    <?= Html::csrfMetaTags() ?>
    <title><?php echo Html::encode($this->title); ?></title>

    <link rel="shortcut icon" href="<?php echo Yii::getAlias('@web/themes/dcu') ?>/assets/images/favicon.png" type="image/x-icon" />


     <link rel="stylesheet" type="text/css" href="<?php echo Yii::getAlias('@web'); ?>/themes/dcu/assets/css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="<?php echo Yii::getAlias('@web'); ?>/themes/dcu/assets/css/bootstrap-responsive.min.css" />
       <link rel="stylesheet" type="text/css" href="<?php echo Yii::getAlias('@web'); ?>/themes/dcu/assets/css/gbu.csss" />
        <link rel="stylesheet" type="text/css" href="<?php echo Yii::getAlias('@web'); ?>/themes/dcu/assets/css/font-awesome.css" />

<?php $this->head()?>
</head>
<body>
    <?php $this->beginBody() ?>
    <span class="striept"></span>
    <div id="wrap">
        <div class="container" id="page">
            <div class="row header">
                <div class="span7">
                    <a href=<?php Yii::$app->homeUrl ?>><img src="<?php echo Yii::getAlias('@web'); ?>/themes/dcu/assets/images/documentatiecentrum-urk.png" /></a>
                </div>
                <div class="span5 login-form">
                    <?php if (Yii::$app->user->isGuest): ?>
                        <div class="form">
                        </div>
                    <?php else: ?>
                        <ul class="inline">
                            <li>Je bent inlogd als: <?php echo Yii::$app->user->identity->username; ?> </li>
                            <li>
                            </li>
                        </ul>
                    <?php endif; ?>
                </div>
            </div>
            <div class="row">
                <div class="span12 zoeken">
                    <div class="input-append">

                    </div>
                </div>
            </div>

        </div>

        <div class="container-fluid dark topmargin">
            <div class="container">
                <div class="row">
                    <div class="span8">
                        <h3>Onze partners</h3>
                        <div class="row-fluid">
                            <div class="span4">

                            </div>
                            <div class="span4">

                            </div>
                            <div class="span4">

                            </div>
                        </div>
                    </div>
                    <div class="span4">
                        <div class="row-fluid">
                            <h3>Ook meehelpen?</h3>
                            <p>Met uw steun zorgt u er samen met ons voor dat ons grote cultuurbezit, 'oenze taol', blijft bestaan!</p><p>Steun ons project en doneer een bedrag op onze bankrekening: 11.40.24.820 Rabobank Urk. Bedankt voor uw hulp!</p>
                            <a class="btn btn-primary" href="https://www.justgiving.nl/nl/charities/83-stichting-%20urker-taol" target="_new">Direct doneren</a>
                            <a class="btn btn-primary" href="<?php echo Yii::$app->basePath; ?>donateursformulier.pdf" target="_new">Donateursformulier</a>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="span12 copyright">
                    </div>
                </div>
            </div>
        </div>
    </div>
   </body>
    <?php $this->endBody() ?>
</html>
<?php $this->endPage() ?>

我认为是bootsrap的问题,因为其他所有的CSS文件都OK。

最佳答案

AssetBundle代表资源文件的集合,如CSS、JS等

Assets 包可以依赖于其他 Assets 包。向 View 注册 Assets 包时,将自动注册其所有依赖的 Assets 包。

请引用以下链接

Yii2 AssetBundle API DOC

AssetBundle Example

首先创建一个ThemeAsset AssetBundule。

<?php

    namespace app\assets;
    use yii\web\AssetBundle;

    class ThemeAsset extends AssetBundle
    {
        public $basePath = '@webroot';
        public $baseUrl = '@web';
        public $css = [
             '/themes/dcu/assets/css/bootstrap.css',
             '/themes/dcu/assets/css/bootstrap-responsive.min.css',
             '/themes/dcu/assets/css/gbu.css',
             '/themes/dcu/assets/css/font-awesome.css',
        ];
        public $js = [      
             .... 
             js file here
             .... 
        ];
        public $jsOptions = [
             ....
             js options here
             ....
        ];
        public $depends = [
             ....
             dependent asset bundles here
             eg: 'yii\bootstrap\BootstrapAsset'
             ....
        ];
    }
?>

现在在您的 View 文件中注册ThemeAsset

<?php
   use app\assets\ThemeAsset;
   ThemeAsset::register($this);
?>

关于php - yii2 中的 Css 和 bootstrap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37821048/

相关文章:

php - 选取框显示在两行而不是一行 - HTML 和 CSS

php - 具有热链接保护和低内存使用率的 Laravel 下载响应

php - echo 在 PHP 中的使用

html - 一次应用多个 css 值

javascript - 图像悬停上的内容框?

javascript - 如何在 jQuery 中无限水平滚动图像?

PHP:使用 index.php 作为 Bootstrap 是否安全?

javascript - 获取不带 "id"属性的 td 的内容

javascript - 如果边界上有图像,则为 border-radius

javascript - 单击时图像在 Google Chrome 浏览器上跳转