Architecture

Data Types

The core of MV architecture based on data types for models and forms, that can be both typical for programming (string, integer etc), or special ones for more convenient operation (files, images, arrays of images, group). All data types have their fields in SQL table except for "many_to_many" type (for this type a special linking table will be created), and also "many_to_one" which is the reverse count of records by foreign key. The types are being assigned to special attributes that specify special settings for the field.

To create a field in a model or form you need to fill an array of 3 required parameters and one optional:

  1. Text field name
  2. Data typeŃ…
  3. Field name in SQL table
  4. An array of additional parameters
array("Activation", "bool", "active", array("on_create" => true))

array("Name", "char", "name", array("required" => true))

array("Album", "enum", "album", array("foreign_key" => "Albums", "empty_value" => true))

array("Rating", "float", "rating")

array("Position", "order", "order")

array("Image", "image", "image", array("required" => true))

Models and Views

The main components of MV are models - classes for data management in SQL tables and views (templates) - PHP files for HTML code generation. The model consists of several data types that act within the model as objects to interact with each other and with other models. Based on model fields the Admin Interface will be automatically created.

class News extends Model
{
    protected $name = "News";

    protected $model_elements = array(
        array("Activation", "bool", "active", array("on_create" => true)),
        array("Date", "date", "date", array("required" => true)),
        array("Name", "char", "name", array("required" => true)),
        array("News", "text", "content", array("rich_text" => true)),
        array("Comments", "many_to_one", "comments", array("related_model" => "Comments"))
    );

    public function display()
    {
        $rows = $this -> select(array("active" => 1, "order->desc" => "date"));
        $html = "";

        foreach($rows as $row)
        {
            $html .= "<h2>".$row["name"]."</h2>";
            $html .= "<p>Date: <span>".I18n :: firmatDate($row["date"])."</span></p>";
            $html .= "<p>".$row["content"]."</p>";  
        }

        return $html;
    }
}

PHP becomes a template generator, template files are located in a special folder and included in the result of processing of the passed URL by Router. The search of required records in SQL tables, and calls of model methods to display data will occur in the template.

<div id="content">
    <h1><? echo $news -> name; ?></h1>
    <p class="date"><? echo I18n :: formatDate($news -> date); ?></p>
    <? echo $news -> content; ?>
</div>

Routing

Including of required templates (views) is performed with the help of Routing based on the passed URL. The requested URL is divided into parts and analyzed by a Router after that a template will be included. When analyzing the URL regular expressions aren't applied, to increase performance a comparison with the standard templates will occur as described in General principles of templates section.

The template is included in any case, even if no match was found, a default template will be included, from which it is possible to call 404 error.

"contacts/" => "view-contacts.php",

"user/login/" => "client/view-login.php",

"news/*/" => "view-news.php"

Forms

Forms are created based on data types. Also, it is possible to create forms based on models, using the structure of fields already created. MV has tools to validate form fields, display fields and their errors, assemble messages, quickly create records in SQL tables based on form data.

<?
$form_news = new Form("News");

$fields = array(
    array("Name", "char", "name", array("required" => true)),
    array("Email", "email", "email", array("required" => true)),
    array("Phone", "phone", "phone"),
    array("Question", "text", "question", array("required" => true))
);

$form_contact = new Form($fields);
?>

<form method="post" action="">
    <table>
        <? echo $form_contact -> display(); ?>
    </table>
    <p><input type="submit" value="Send" /></p>
</form>

Admin Panel

There is a part of MV called Admin Panel that automatically creates the interface for model management. All active models have their own section in Admin Panel where it is possible to create, edit and delete records.

The following components are the part of Admin Panel:

  • lists of all records of the model
  • records management (CRUD)
  • deleting in a bin with an option to restore
  • search (filtering) of records on all fields
  • mass operations with records
  • change history of all fields for each record
  • administrators with different level of rights
  • operations history of administrators
  • file manager