problem in layout

I have created layouts for my admin page just for a test…

in

views/

layouts/

 main.php


 myadminlayout.php



<?php

use yii\helpers\Html;

use yii\bootstrap\Nav;

use yii\bootstrap\NavBar;

use yii\widgets\Breadcrumbs;

use app\assets\AppAsset;


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

/* @var $content string */


AppAsset::register($this);

?>

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

    <title><?= Html::encode($this->title) ?></title>

    <?php $this->head() ?>

</head>

<body>


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

<div class="wrap">

// I remove the navbar just for a test.

   <div>

       // some logo.jpg here.....

   </div>

    <div class="container">

        <?= Breadcrumbs::widget([

            'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],

        ]) ?>

        <?= $content ?>

    </div>

</div>


<footer class="footer">

    <div class="container">

        <p class="pull-left">&copy; My Company <?= date('Y') ?></p>

        <p class="pull-right"><?= Yii::powered() ?></p>

    </div>

</footer>


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

</body>

</html>

<?php $this->endPage() ?>




In views/admin.php how can I call the layout myadminlayout.php

Thank you in advance.

In controller (in init() for all actions or in some actions that you want), use this code:


$this->layout = 'myadminlayout';

Thank you for the reply…so in every action I will include this code

Is there a way also to make this global only in my admin page ?

so that I will not call anymore in every actions in my controller

Thank you in advance.

You should create AdminController, example:

Create AdminController


namespace app\components;


use Yii;

use yii\web\Controller




class AdminController extends Controller

{


    public function init()

    {

        parent::init();

        $this->layout = 'myadminlayout';

    }


}

Then in every your Controller in Admin, let’s extend app\components\AdminController instead of yii\web\Controller

And you may be want to check Admin role in AdminController (use AccessControl in behaviors, or check in init() )

Okay I will try.

Thank you

Okay I will try.

Thank you