Store your views at the views folder.

Views are PHP files whose content is HTML most of the time. PHP tags should only be used to echo values from variables passed by.

An example displaying book model:

<div class="book book-<?php echo $book->ID ?>">

    <h1><?php echo $book->title ?></h1>

        <li>Year: <?php echo $book->year ?></li>
        <li>Publisher: <?php echo $book->publisher ?></li>

    <p><?php echo $book->description ?></p>


NOTE: There is no PHP logic in the view, just pure HTML, perfect for the designer to handle. Logic is placed in the controller.

You can place your views as please within the views folder.

Let’s assume that the view file from above is named profile.php, you can place it in a path like this:

 |---> [views]
 |      |---> [books]
 |      |      |---> profile.php

The key locator for this view within the Lightweight MVC will be:



Multiple ways of calling for views. The get() function will return a view and the show() function will echo it.

Example using books.profile from above:

Within a Controller

php, you can place it in a path like this:

$this->view->get( 'books.profile' );

Within Main.php

Example accessing through the engine:

$this->mvc->view->get( 'books.profile' );

Within THEME template

Example will print a view:

<?php theme_view( 'books.profile' ) ?>


Pass parameters to the view like this:

$this->view->get( 'books.profile', ['book' => Book::find(1), 'css' => 'book-test'] );

<?php theme_view( 'books.profile', ['book' => Book::find(1), 'css' => 'book-test'] ) ?>

The parameters passed by in this example are 2. First one is a book model with the ID equals to 1 and second one is a string css class named book-test.

Use them in the view like this:

<div class="<?php echo $css ?>">

    <h1><?php echo $book->title ?></h1>


Theme customizations

Plugin views can be customized in any theme. To do this, copy and paste the related view file in the theme under the same views folder hierarchy. Lightweight MVC will give priority to the view located in the theme.

Example of copying profile.php, from the example above, in a theme:

 |---> [views]
 |      |---> [books]
 |      |      |---> profile.php