Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
164 views
in Technique[技术] by (71.8m points)

php - Css and bootstrap in yii2

I'm quite new to Yii2 and I have created a layout page, but my CSS doesn't work fully. It only loads parts of it. Can somebody help me please?

My layout:

<?php
namespace appviewslayouts;

use yiiootstrapAlert;
use yiiootstrapActiveForm;
use yiihelpersUrl;
use yiihelpersHtml;
use yiiootstrapNavBar;
use yiiootstrapButton;
use appmodelsSearch;
use yiiootstrapNav;
use appassetsAppAsset;
use appmodelsLoginForm;
use yiiwebView;
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() ?>

I think the problem is the bootsrap, because all the other CSS files are all OK.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

AssetBundle represents a collection of asset files, such as CSS, JS, etc.

An asset bundle can depend on other asset bundles. When registering an asset bundle with a view, all its dependent asset bundles will be automatically registered.

please refer below link

Yii2 AssetBundle API DOC

AssetBundle Example

First create one ThemeAsset AssetBundule.

<?php

    namespace appassets;
    use yiiwebAssetBundle;

    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: 'yiiootstrapBootstrapAsset'
             ....
        ];
    }
?>

Now register the ThemeAsset in your view file

<?php
   use appassetsThemeAsset;
   ThemeAsset::register($this);
?>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...