File: D:/HostingSpaces/SBogers10/keystud.komma-mediadesign.nl/wwwroot/kms/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;
/*
* @property Alert
* Contains an alert object.
*/
protected $Alert;
/*
* lang
*/
protected $lang;
protected $urls;
/*
* @property Functions
* Contains an functions object.
* This object contains functions which can be used by a controller.
*/
public $Functions;
public function __construct()
{
$this->Alert = new Alert();
$this->Functions = new Functions();
}
/*
* 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'))
{
include $path;
}
$modelName = ucfirst($name) . '_Model';
$this->Model = new $modelName;
}
}
/*
* Initialise
* - Load Language
* - Load Alerts
* - Load Main navigation
*/
public function init()
{
// Create new view
$this->View = new View();
// Menu
if(class_exists('Main_Nav'))
{
$MainNav = new Main_Nav();
$this->View->setData('main_menu',$MainNav->get());
}
// Load languages and alerts
$this->loadLanguage();
$this->loadAlerts();
}
/*
* Load Language
*/
public function loadLanguage()
{
if(defined('URL_LANG'))
{
$LanguageHandler = new LanguageHandler();
$LanguageHandler->set(URL_LANG);
$this->View->setLang($LanguageHandler->get());
$this->View->setUrls($LanguageHandler->getUrls());
$this->lang = $LanguageHandler->get();
$this->urls = $LanguageHandler->getUrls();
$flagMenu = $LanguageHandler->displayMenu();
$this->View->setData('lang_menu',$flagMenu);
}
}
/*
* Load Alerts
*/
public function loadAlerts()
{
if($alert = $this->Alert->get())
{
$this->View->setData('alert',$alert);
}
}
}