File: D:/HostingSpaces/SBogers55/frankdeturck.nl/wwwroot/lib/mvc/controller.class.php
<?php
/**
* controller.class.php
* Created by Komma Mediadesign.
* Author: mike
* Date: 3/19/13
*/
class Controller {
/*
* @property View
* Contains a view object.
*/
protected $View;
/*
* @property Model
* Contains a model object.
*/
protected $Model;
/*
* Language
*/
protected $lang = array();
protected $urls = array();
public function __construct()
{
// Set language and url for conversion
$Translator = new Translator(URL_LANG);
$this->lang = $Translator->get();
$this->urls = $Translator->getUrls();
}
/*
* LoadModel checks if the requested file exists.
* If so, it includes it in this template and creates a new Model;
*/
public function loadModel($name)
{
$path = DOCUMENT_ROOT . 'app/models/m_' . strtolower($name) . '.class.php';
if(file_exists($path))
{
if( ! class_exists($name . '_Model'))
{
require_once $path;
}
$modelName = ucfirst($name) . '_Model';
// Create model
$this->Model = new $modelName;
// Make language available for model
$this->Model->setLang($this->lang,$this->urls);
}
}
/*
* Initialise
*/
public function init($name)
{
// Create new view
$this->View = new View();
// Set language for the view
$this->View->setLang($this->lang,$this->urls);
// Body Id
$this->View->setData('body_id',strtolower($name));
}
}