Pre-Installed Models

Pages (Pages menu)

Pages Menu Model is designed for management of standard webpages that have no dynamically generated content from forms or other models. The content of pages is inserted into text field in Admin Panel or Visual Editor. Also by default this model was designed as a tree, one of it’s fields has "parent" type, as a result we can create inner pages.

The structure of model, "pages.model.php" file in "models" folder, and also SQL table of "Pages" model (SQLite database).

<?
class Pages extends Model
{
    protected $name = "Pages Menu";

    protected $model_elements = array(
        array("Activate", "bool", "active", array("on_create" => true)),
        array("Show in Menu", "bool", "in_menu", array("on_create" => true)),
        array("Name", "char", "name", array("required" => true)),
        array("Title", "char", "title"),
        array("Parent section", "parent", "parent"),
        array("Link", "url", "url", array("unique" => true)),
        array("Redirect", "redirect", "redirect"),
        array("Position", "order", "order"),
        array("Content", "text", "content", array("rich_text" => true))
    );
}
?>

CREATE TABLE "pages"( 
  "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  "active" INTEGER,
  "in_menu" INTEGER,
  "name" VARCHAR, 
  "title" VARCHAR, 
  "parent" INTEGER, 
  "url" VARCHAR, 
  "redirect" VARCHAR, 
  "order" INTEGER, 
  "content" TEXT);

By default, this model has 2 own methods (other methods are inherited from Model class).

  • defineCurrentPage(Router $router)

Defining parameters when searching a page in database ("pages" table) based on passed URL. Returns an array of parameters for "findRecord()", method, which is inherited from Model class. "findRecord()" method in it’s turn builds SQL query based on passed parameters and in case of success returns object of "Record" class, that contains the list of all the page fields from the database.

Samples of Use

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

echo $content -> name;
echo $content -> title;
echo $content -> content;
  • displayMenu($parent [, $only_links])

Function to output menu items. Returns a list of links, wrapped into "li" html tags.Active menu item will have a class "active", and the first element will have a class "first". The attribute of "href" link is being build based on id and url fields by the following method: if a page has a filled "url" field (for example, about), then "/about/" link will be created, or the page id will be used for a link as "/page/17/".

Parameters

  • $parent (mandatory) id of parent menu item. To display root list of pages use "-1".
  • $only_links (optional) If you pass a value "A" to this parameter, then only a sequence of links will be displayed without wrapping them into.
  • Samples of Use

    echo $mv -> pages -> displayMenu(-1);
    echo $mv -> pages -> displayMenu(5);
    echo $mv -> pages -> displayMenu(17, "A");
    

    Blocks (text blocks, fragments )

    Text segments of information that is used to display information in top/bottom parts of the website or sidebars.This information can be displayed on all pages or can be changed depends on page view. The model by default has no own methods, they all are inherited from Model class. The structure of the model, "blocks.model.php" in "models" folder, and also SQL table of "Blocks" model (SQLite).
    <?
    class Blocks extends Model
    {
        protected $name = "Text blocks";
    
        protected $model_elements = array(
            array("Activation", "bool", "active", array("on_create" => true)),
            array("Name", "char", "name", array("required" => true)),
            array("Content", "text", "content", array("rich_text" => true))
        );
    }
    ?>
    
    CREATE TABLE "blocks" (
      "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
      "active" INTEGER,
      "name" VARCHAR,
      "content" VARCHAR);
    
    Samples of Use
    //Extract data (records) from database and output data on the screen
    $top_content = $mv -> blocks -> findRecord(array("id" => 1, "active" => 1));
    $left_content = $mv -> blocks -> findRecord(array("id" => 43));
    
    echo $top_content -> name;
    echo $left_content -> content;
    

    SEO (data for SEO optimization )

    The model is used to generate meta tags in html page, and also creates and edits "robots.txt" file. This model differs from previous two ones by the fact that it represents a Simple Model. More details about model of this type can be found in Simple Models section. The structure of model, "seo.model.php" file in "models" folder, and also SQL table of "seo" model ( MySQL).
    <? 
    class Seo extends Model_Simple
    {
       protected $name = "SEO parametrs";
    
       protected $model_elements = array(
           array("Title", "char", "title"),
           array("Keywords", "text", "keywords"),
           array("Description", "text", "description"),
           array("Robots.txt", "text", "robots")
       );
    }
    ?>
    
    CREATE TABLE `seo` (
      `key` varchar(100) NOT NULL,
      `value` text,
      PRIMARY KEY (`key`)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
    

    Samples of Use

    Meta tags and page titles are generated by "views/main-header.php".
    <title><? echo $mv -> seo -> title; ?></title>
    <meta name="description" content="<? echo $mv -> seo -> description; ?>" />
    <meta name="keywords" content="<? echo $mv -> seo -> keywords; ?>" />
    
    By default, the titles and meta tags are getting their values from "seo" table, however it is possible to pass additional values to this model object to support unique values.
    $content = $mv -> pages -> defineCurrentPage($mv -> router);
    $mv -> seo -> mergeParams($content, "name");
    
    In this case in method "mergeParams()" the following actions are happening:
    1. An object of Record class is being passed having all the fields of the webpage (or other resource) from database.
    2. If there are filled fields in the object such as title, keywords, description, then default values from "seo" tables will be totally replaced with data from these fields.
    3. If one of these 3 fields cannot be found in "$content" object, then a second optional parameter of "mergeParams()" method will be used.
    4. With this parameter a name of the field can be passed, the value of which will be added to default values of "seo" table to support unique meta tags on different webpages.
    5. Also it is possible to call "mergeParams()" method with only parameter that contains text line. This line will be added to default parameters the same way as the method with 2 parameters.
    $mv -> seo -> mergeParams("Our activities");
    $mv -> seo -> mergeParams("Marker board 120х200");