3. Layouts

Don't repeat yourself

Each module need a file inside the views to be the default HTML for all actions, we mean, all .phtml scripts will be rendered inside this file. It's called layout because it contain all HTML parts which are repeated in all pages from your system. Is not necessary to do any include or require to include this file, SuitUp do it for you automatically.

Where you include on your layout HTML the variable <?php echo $content; ?> is where will be rendered (printed) the content from view.

The layout

File: ModuleDefault/views/layout.phtml

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <!-- ... -->
    </head>
    <body>

        <nav></nav>
        <div class="sidebar"></div>
        <div class="content">

            <!-- Here the content will be rendered (printed) -->
            <?php echo $content; ?>
        </div>

        <!-- Query SQL monitoring -->
        <?php echo $queryLog; ?>
    </body>
</html>

If you enabled the 'SQL monitoring', point in your layout where you want this HTML injection to be printed, generally at the end of the file, but before </body> tag.

Layout messages

Inside any action from any controller you can call the method $this->addMsg("mensagem", MsgType::SUCCESS, true); to messages that will be displayed in the layout after a redirect or $this->addMsg("mensagem", MsgType::SUCCESS); to messages that will be direct displayed in the layout.

For this work well add these lines below anywhere in your layout.phtml file

1
2
3
4
5
6
7
8
9
<!-- System messages -->
<?php foreach ($layoutMessages as $type => $msgs): ?>
    <div class="alert alert-<?php echo $type; ?>">
        <a href="#" class="close">&times;</a>
        <?php foreach ($msgs as $msg): ?>
            <p><i class="fa fa-check"></i> <?php echo $msg; ?></p>
        <?php endforeach; ?>
    </div>
<?php endforeach; ?>

See more about this [[here|2.1-MvcAbstractController-(en)#addMsg]].