Finishing touches

You will need to apply some visual tweaks to your UI to make it appear more clean and appealing.

Creating a new layout to support pages generated by Gii

Here is how our UI looks right now, given that one record is already inserted into the services table:

Creating a new layout to support pages generated by Gii

Given our spartan visuals from Chapter 2, Making a Custom Application with Yii 2, you most probably did not expect much from the UI generated by Gii anyway; however, this obviously has some serious layout problems. The issue is that we jumped too far with this step, as we have not bothered with the looks of our application until now. Chapter 4, The Renderer, talks about rendering a system in Yii 2. However, we can take a glimpse into the future and prepare a bare minimum of the view code to enable the standard Yii 2 project design, as you may have seen in the basic application template already.

Our only issue, really, is the too-limited layout file. Let's recall what our views/layouts/main.php looks like:

<!DOCTYPE html>
<html>
<head>
    <title>CRM</title>
</head>
<body>
    <?= $content; ?>
</body>
</html>

This is not what Gii expects from us. To not delve into much detail, which will be given in Chapter 4, The Renderer, we'll just replace this layout with the one copied directly from the basic application template:

<?php
use yiihelpersHtml;

yiiootstrapBootstrapAsset::register($this);
yiiwebYiiAsset::register($this);
?>
<?php $this->beginPage() ?>
    <!DOCTYPE html>
    <html lang="<?= Yii::$app->language ?>">
    <head>
        <meta charset="<?= Yii::$app->charset ?>"/>
        <title><?= Html::encode($this->title) ?></title>
        <?php $this->head() ?>
        <?= Html::csrfMetaTags() ?>
    </head>
    <body>
    <?php $this->beginBody() ?>
    <div class="container">
        <?= $content ?>
        <footer class="footer"><?= Yii::powered();?></footer>
    </div>
    <?php $this->endBody() ?>
    </body>
    </html>
<?php $this->endPage() ?>

This is the only time we need to do something without using Gii to satisfy our end-to-end tests, and this is a one-time issue because all of the future sections generated by Gii will use the same layout without any changes.

Except various useful calls such as inserting an HTML language attribute, inserting a metatag with a charset, and HTML encoding the title of the page, pay attention to the highlighted lines. They are the framework of the Yii 2 renderer. We will explore it in Chapter 4, The Renderer.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.225.57.164