Answer the question
In order to leave comments, you need to log in
How to set dynamic title MVC?
I can't figure out how to dynamically set the title on the page. I am writing a self-made CMS using the MVC template.
Here is the view class, in the render method I include the main template
class View
{
public $title;
public $template_path;
public $view_path;
public function __construct()
{
$module = strtolower(Settings::get('module'));
$modules = Settings::get('modules');
$template_path = Settings::get('root_path').$modules[$module]['template'];
$this->template_path = $template_path;
$controller = strtolower(Settings::get('controller'));
$view_path = Settings::get('root_path').'/modules/'.$module.'/'.'views'.'/'.$controller.'/';
$this->view_path = $view_path;
}
public function render($view, Array $data = null)
{
if(!empty($data))
{
extract($data);
}
include $this->template_path;
}
<?php
require_once APP_PATH.'/Core/URL.php';
require_once APP_PATH.'/Core/Request.php';
?>
<!DOCTYPE html>
<html lang="ru">
<head>
<link rel="stylesheet" type="text/css" href="/css/main.css">
<title><?=$this->title?></title>
</head>
<body>
<div id="container">
<div id="wrapper">
<div id="clear">
<?php include 'header.php'; ?>
<?php include $this->view_path.$view; ?>
</div>
</div>
<footer>
</footer>
</div>
</body>
</html>
<?php
$this->title = "Главная";
?>
<aside class="bar left">
</aside>
<aside class="bar right">
</aside>
<main>
<div>Главная </div>
</main>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question