Launch of simple website with MV

In this section we will describe how to launch a simple website on MV framework. Let’s assume that you already have MV framework installed and launched.

Suppose, we have an HTML template coded.

<head>
    <title>Test website</title>
    <link rel="stylesheet" type="text/css" href="/media/css/style.css" />
</head>
<body>
    <div id="header">
        <ul>
            <li class="active"><a href="/about/">About us</a></li>
            <li><a href="/services/">Services</a></li>
            <li><a href="/contacts/">Contacts</a></li>
        </ul>
    </div>
    <div id="content">
        <h1>Page title</h1>
        <p>Page content</p>
    </div>
    <div id="footer"></div>
</body>

Here we are going to use “Pages” model, that is described in Pre-Installed Models section. Models for websites have been already created, we will only work with templates from "views" folder. More details about Routing can be found in the following sections: General Principles of Templates, Index, default and 404 templates.

1. Cutting template into header/footer parts

Most of websites have repeating top/bottom parts which are called header/footer. These parts are separated from the main template into individual files and being included in the top/bottom parts of the webpage. In MV header/footer are presented by "main-header.php" and "main-footer.php" files from “views” folder.

Let’s separate top and bottom parts in our template and save them into these files. The content of "main-header.php".

<head>
   <title><? echo $mv -> seo -> title; ?></title>
   <meta name="description" content="<? echo $mv -> seo -> description; ?>" />
   <meta name="keywords" content="<? echo $mv -> seo -> keywords; ?>" />
   <link rel="stylesheet" type="text/css" href="<? echo $mv -> media_path; ?>css/style.css" />
</head>
<body>
    <div id="header">
        <ul>
             <? echo $mv -> pages -> displayMenu(-1); ?>
        </ul>
    </div>

To display a menu we are using "displayMenu()" method of “Pages” model. As a parameter it accepts an id of parent section, from which we show the menu items. If we display menu items of root section, then an id parameter will be -1 Additional samples of menu display can be found in Pre-Installed Models section.

The content of main-footer.php

    <div id="footer"></div>
</body>

2. Home page template

Open "view-index.php" file below you will find a default content without the first 2 lines, that can be deleted.

<?
//looking for a record in database with the content of main page
$content = $mv -> pages -> findRecord(array("url" => "index"));

/if not found, show 404 error 
$mv -> display404($content);

//assemble parameters for meta tags
$mv -> seo -> mergeParams($content, "name"); 

//Include template header and display fields from database
include $mv -> views_path."main-header.php";
?>
    <h1><? echo $content -> name; ?></h1> 
    <? echo $content -> content; ?>
<?
include $mv -> views_path."main-footer.php"; //Include template footer
?>

By adding elements of our template we get the final version of the file "view-index.php".

<?
$content = $mv -> pages -> findRecord(array("url" => "index"));
$mv -> display404($content);

include $mv -> views_path."main-header.php";
?>
    <div id="content">
        <h1><? echo $content -> name; ?></h1>
        <? echo $content -> content; ?>
    </div>
<?
include $mv -> views_path."main-footer.php";
?>

3. Inner page default template

This template will be shown when a non-homepage was requested and all other templates have been missed by router. This is not a 404 page yet, although in case this page cannot be found when parsing the URL, then we will be redirected to 404 page template.

The final version of "view-default.php", the only difference with home page template is the first line where it looks for a page with a requested URL.

<?
$content = $mv -> pages -> defineCurrentPage($mv -> router);
$mv -> display404($content);

$mv -> seo -> mergeParams($content, "name");
include $mv -> views_path."main-header.php";
?>
    <div id="content">
        <h2><? echo $content -> name; ?></h2>
        <? echo $content -> content; ?>
    </div>
<?
include $mv -> views_path."main-footer.php";
?>

4. 404 error template

If all the steps of finding a page in database have been passed and the page was not found, then 404 error template will be called. There is a special "view-404.php" template file in MV for this case.

<?
$content = $mv -> pages -> findRecord(array("url" => "e404"));

$mv -> seo -> mergeParams($content, "name");
include $mv -> views_path."main-header.php";
?>
    <div id="content">
        <h2><? echo $content -> name; ?></h2>
        <? echo $content -> content; ?>
    </div>
<?
include $mv -> views_path."main-footer.php";
?>

5. Website Management

Now when all the templates are configured, we can open Admin Panel, which is located at "/adminpanel/" (login/password - "root" / "root" by default). In Pages Menu section we can create, edit and delete pages. The page with the "Link" field value as “index”, will be the main page of the website. The content for 404 error page will be taken from the page with the "Link" field as "e404".