Pre-installed models
Pages menu
The Page menu model is designed to manage regular site pages that do not have specially generated content from forms or other models. Page content is entered in the administrative panel in the text area or visual editor. Also, initially this model is created as a tree-like one, one of its fields has the parent type, as a result of which it is possible to create internal subsections.
Model structure, file models/pages.model.php.
class Pages extends Model
{
protected $name = 'Pages menu';
protected $model_elements = [
['Active', 'bool', 'active', ['on_create' => true]],
['Show in menu', 'bool', 'in_menu', ['on_create' => true]],
['Name', 'char', 'name', ['required' => true]],
['Title', 'char', 'title'],
['Parent section', 'parent', 'parent'],
['Url', 'url', 'url', ['unique' => true]],
['Redirect', 'redirect', 'redirect'],
['Position', 'order', 'order'],
['Content', 'text', 'content', ['rich_text' => true]]
];
}
Initially, this model contains 2 of its own methods. Other methods are inherited from the base class Model.
- defineCurrentPage(Router $router)
Defines parameters for searching for a page in the pages table based on the passed URL. Returns an array of parameters for the find() method, which is inherited from the Model class. The find() method, in turn, builds an SQL query based on the passed parameters and, if successful, returns a Record class object containing a list of all page fields from the database.
$content = $mv -> pages -> defineCurrentPage($mv -> router);
echo $content -> name;
echo $content -> title;
echo $content -> content;
- displayMenu($parent)
Function for displaying a list of menu items. Returns a list of links for the ul tag.
The active menu item will have the class 'active'. The href link attribute is built based on the id and url fields according to the following principle: if the page has a filled url field (for example 'about'), then a link /about will be created, or the page id will be used and a link of the form /page/17 will be built.
$parent is a required parameter, the Id of the parent menu section. The value -1 is used to display the root list of pages.
//Output from the root section
echo $mv -> pages -> displayMenu(-1);
//Output from section with id=5
echo $mv -> pages -> displayMenu(5);
Text blocks
Text fragments of information that are typically used to display HTML at the top or bottom of a site or in sidebars. This information can be displayed on all pages or change depending on the page view. The model initially does not have its own methods, all are inherited from the Model class.
Model structure, file models/blocks.model.php.
class Blocks extends Model
{
protected $name = 'Text blocks';
protected $model_elements = [
['Active', 'bool', 'active', ['on_create' => true]],
['Name', 'char', 'name', ['required' => true]],
['Content', 'text', 'content', ['rich_text' => true]]
];
}
Examples of usage, retrieving a record from a database and displaying fields.
$top_content = $mv -> blocks -> find(['id' => 1, 'active' => 1]);
$left_content = $mv -> blocks -> find(['id' => 43]);
echo $top_content -> name;
echo $left_content -> content;
SEO parameters
The model is used to form meta tags in the HTML code of the page, and also edits the robots.txt file. This model differs from the previous two in that it is a simple model. More information about this type of model can be found in the Simple models section.
Model structure, seo.model.php file in the models folder.
class Seo extends ModelSimple
{
protected $name = 'SEO parameters';
protected $model_elements = [
['Title', 'char', 'title', ['help_text' => 'The default title value for all pages']],
['Keywords', 'text', 'keywords', ['help_text' => 'Keywords (meta keywords) by default for all pages']],
['Описание', 'text', 'description', ['help_text' => 'Description (meta description) by default for all pages']],
['Robots.txt', 'text', 'robots', ['help_text' => 'Contents of the robots.txt file']],
['Meta data in head', 'text', 'meta_head', ['help_text' => 'Meta tags, counters, plugins']],
['Meta data in body', 'text', 'meta_footer', ['help_text' => 'Counters and plugins']]
];
}
Examples of use.
Formation of meta tags and page titles, usually located in the views/main-header.php file.
<title><? echo $mv -> seo -> title; ?></title>
<meta name='description' content='<? echo $mv -> seo -> description; ?>' />
<meta name='keywords' content='<? echo $mv -> seo -> keywords; ?>' />
<?
//Combine record parameters with general seo data
$content = $mv -> pages -> defineCurrentPage($mv -> router);
$mv -> seo -> mergeParams($content, 'name');
//Combine with the text string
$mv -> seo -> mergeParams('Our activities');
$mv -> seo -> mergeParams('Marker board 120x200');
//Output of general metadata and counters
echo $mv -> seo -> displayMetaData('head');
echo $mv -> seo -> displayMetaData('footer');
?>
In this case, the following actions occur in the mergeParams() method:
- A Record class object is passed, containing all the page fields from the database.
- If the object contains filled fields with the names title, keywords or description, then the default values from the seo table will be completely replaced by the data of these fields.
- If any of the three fields is not found in the object, then the second optional parameter of the mergeParams() method is used.
- This parameter can be passed the name of the field, the value of which will be added to the default values from the seo table to maintain the uniqueness of meta tags on different pages.
- You can also call the mergeParams() method with a single parameter, which will contain a text string. This string will be added to the default parameters similar to calling the method with two parameters.
Previous section
Launching a simple website