Warm tip: This article is reproduced from serverfault.com, please click

small body using custom template yii2

发布于 2020-11-30 20:07:59

I'm trying to use the Architect Free Template in a yii2 basic Application.

I have an issue when I use the tags

<?php $this->beginBody() ?> and <?php $this->endBody() ?>

It makes the body content very small, as you can see on this pic:

picture of small content

If I don't use the tags, it looks like this:

picture of how it should look

If I don't use the tags, the Javascript events (like validations) don't work properly.

So what can I do in this case?

Main.php code:

<?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() ?>

UPDATE:

I checked AppAsset.php file and I noticed if i comment the line what says "yii\bootstrap\BootstrapAsset" the body page backs to normal but without any bootstrap style.

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
    // );
}
Questioner
Ernesto España
Viewed
0
Ernesto España 2020-12-18 06:37:30

Sorry for bother i found why its failing, as @ustmaestro said, yii2 has a different bootstrap version and the template uses bootstrap4.

After install the yii2 bootstrap4 package it works perfectly.

have to change the code to insert bootstrap4 functions.

Greetings.