Pre-installed models

Pages

Pages menu model was designed to manage standard webpages that have no dynamically generated content like forms, galleries and others. The content of pages is inserted into WYSIWYG text field in admin panel. Also, by default this model was designed as a tree, one of its fields has a "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)

Performs searching of the page in database ("pages" table) based on passed URL. Returns an object of Record type, to display page fields inside the template.

Samples of use

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

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

This function outputs 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 the 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 list elements.

Samples of use

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

Blocks (text blocks, html fragments)

Text segments of information that is used to display information in top/bottom parts of the website or in sidebars. This information can be displayed on all pages or can be changed depending 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 at the head of html page, and also creates and edits "robots.txt" file. This model differs from previous two because 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 title are generated in "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 title and meta tags are getting their values from "seo" table, however it is possible to pass additional values to seo model object to support unique values for effective SEO optimization.
$content = $mv -> pages -> defineCurrentPage($mv -> router);
$mv -> seo -> mergeParams($content, "name");
In this case in method "mergeParams()" the following actions happen:
  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 one parameter that contains text string. This string will be added to default parameters the same way as in case with 2 parameters.
$mv -> seo -> mergeParams("Our activities");
$mv -> seo -> mergeParams("Marker board 120х200");