Original question:
I updated my files as instructed, and now I require a review. Please point out the most minute things out to me for me to have better code. Once again, efficiency, elegance, and performance is what I need. Also, please point out places where better code can be used (for places like loading a template, I need to find a better way to load a template).
Model:
<?php
class Model {
public $params;
public $site_url;
public $theme;
public function __construct($global) {
$this->site_url = $global['site_url'];
$this->theme = $global['theme'];
}
}
View:
<?php
class View {
private $model;
private $controller;
public function __construct($model, $controller) {
$this->model = $model;
$this->controller = $controller;
}
public function createPage($path) {
$this->content = $model->replaceParams(file_get_contents($path));
return $this->content;
}
public function createParam($key, $value) {
$model->params['{' . $key . '}'] = $value;
}
public function replaceParams($content) {
foreach($model->params as $key => $value) {
str_replace($key, $value, $content);
}
return $content;
}
public function pageExists($path) {
return file_exists($path);
}
}
Controller:
<?php
class Controller {
private $model;
public function __construct($model) {
$this->model = $model;
}
public function handlePageLoad($page_name) {
$this->path = $model->site_url . "/app/tpl/skins/" . $model->theme . "/" . $page_name . ".php";
if($view->pageExists($this->path) === true) {
$this->content = $view->createPage($this->path);
return $this->content;
} else {
header('HTTP/1.1 404 Not Found');
return false;
}
}
}
Global:
<?php
function autoload($class_name) {
include "classes/class." . $class_name . ".php";
}
spl_autoload_register('autoload');
$global = array(
'site_url' = 'http://localhost/Projects/HassanCMS',
'theme' = 'v1'
);
$model = new Model($global);
$controller = new Controller($model);
$view = new View($model, $controller);
$view->createParam('site_title', 'HassanTech');