0

Yii2 advanced template, PHP 5.6, Ubuntu 16.04, nginx.

I have following myproject/backend/assets/AppAsset.php:

class AppAsset extends AssetBundle {
    public $basePath = '@webroot';

    public $css = [
        '/css/style.css', 
        '/plugins/iCheck/square/blue.css', 
        '/plugins/datatables/dataTables.bootstrap.css', 
        '/css/AdminLTE.min.css'
    ];

    public $js = [
        'admin/js/common.js',
        'plugins/datatables/jquery.dataTables.js',
        'plugins/datatables/dataTables.bootstrap.js',
        'plugins/iCheck/icheck.min.js' 
    ];

    public $depends = [
        'yii\web\YiiAsset',
        'yii\bootstrap\BootstrapAsset'
    ];
}

Layout has:

use backend\assets\AppAsset;
AppAsset::register($this);

It is my layout main.php, when I have added AppAsset bundle.

<?php
use backend\assets\AppAsset;
use yii\helpers\Html;
use yii\bootstrap\Nav;
use yii\bootstrap\NavBar;
use yii\widgets\Breadcrumbs;

AppAsset::register($this);

/* @var $this \yii\web\View */
/* @var $content string */

?>
<?php //$this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
    <meta charset="<?= Yii::$app->charset ?>">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <?= Html::csrfMetaTags() ?>
    <?php
    //$assets_base = Yii::$app->controller->getAssetsBase();
    ?>

    <title>MyProject</title>
    <?php $this->head() ?>
</head>
<body class="login-page">
<?php $this->beginBody() ?>
<h1>Test!!!</h1>
<?= $content ?>

<?php $this->endBody() ?>
</body>
</html>
<?php

All css and js files are located in public folder web (myproject/backend/web).

When I reload page tag <head> has only:

<meta charset="UTF-8">
    <meta name="viewport" 
  <meta name="csrf-param" 
<meta name="csrf-token"
2
  • Can you show content of your layout (probably main.php)? Commented Jul 14, 2018 at 19:11
  • i`ve updated question with layout Commented Jul 14, 2018 at 19:21

1 Answer 1

3

You should remove comment from this line:

<?php //$this->beginPage() ?>

$this->beginPage() is required to enable output buffering, which is required to inject assets links in the place of $this->head() call.

In general you should not remove any method calls from default layout of app templates, unless you're really know what you're doing - they are there for a reason.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.