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.

Supposed that we have an HTML template.

<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 and footer parts

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

Let’s separate top and bottom parts from our template. 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 displaying can be found in Pre-Installed Models section.

The content of main-footer.php file.

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

2. Home page template

Open "view-index.php" file and remove all initial data from it. Below you can see the index page templete content.

<?
//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);

//Merge 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);
$mv -> seo -> mergeParams($content, "name");

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. Internal page default template

This template will be shown when the anything but homepage was requested and all other templates have been missed by router. This is not a 404 page yet, although in case this page can't 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 searching a page in database have been passed and the page was not found, then 404 error template will be displayed. There is a special "view-404.php" template file in MV initial views for this purpose.

<?
$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 our pages. The page with “index” value in the "Link" field, 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".