just added a new core and moved themes if you want to PM your theme [USER=60]@Propaganda[/USER] ill make the changes
here is new core for mvc, this is the skeleton and can be run with only 7 files
obvs the db class and you can use this for anything not just TT you just need to add home controller, view & model at minute the old TT is spaghetti code but with good classes can be really slimmed down ive been saving classes for some time now so just need to implement them.
index.php
<?php
require_once "core/TTcore.php";
TTcore::run();
TTcore.php
<?php
class TTcore
{
public static function run()
{
self::init();
self::autoload();
self::dispatch();
}
private static function init()
{
// Define path constants
define("DS", DIRECTORY_SEPARATOR);
define("ROOT", __DIR__ . DS);
// Core
require "core/Database.php"; // Extened PDO connection
require "core/Router.php"; // Set Paths
require "core/Controller.php"; // Load Models/Views
// Include all helpers & connection
require_once "helpers/a_start_function.php";
session_start();
}
private static function autoload()
{
// Autoload Classes (Controllers & Models already loaded)
spl_autoload_register ( function ($class) {
$sources = array("classes/$class.php"); // just one for now but it is a array
foreach ($sources as $source) {
if (file_exists($source)) {
require_once $source;
}
}
});
}
private static function dispatch()
{
$router = new Router;
}
}
controller.php (puts models and views into controllers)
<?php
/*
* Base Controller
* Loads the models and views
*/
class Controller
{
// Load model
public function model($model)
{
// Require model file
require_once 'models/' . $model . '.php';
// Instatiate model
return new $model();
}
// Load View (we add data with array $data[] )
public function view($file, $data = [], $inc = false)
{
global $config, $THEME, $LANGUAGE;
// Check for view file
if (file_exists('views/' . $file . '.php')) {
if ($inc) {
require "themes/" . ($_SESSION['stylesheet'] ?: $config['default_theme']) . "/header.php";
require "themes/" . ($_SESSION['stylesheet'] ?: $config['default_theme']) . "/topnavbar.php";
require_once "views/" . $file . ".php";
require "themes/" . ($_SESSION['stylesheet'] ?: $config['default_theme']) . "/footer.php";
} else {
require_once "views/" . $file . ".php";
}
} else {
// View does not exist
die('View does not exist');
}
}
}
router.php (links everything together)
<?php
/*
* App Router Class
* Creates URL & loads core controller
* URL FORMAT - /controller/method/params
*/
class Router
{
protected $currentController = 'Home';
protected $currentMethod = 'index';
protected $params = [];
public function __construct()
{
//print_r($this->getUrl());
$url = $this->getUrl();
// Look in controllers for first value
if (file_exists('controllers/' . ucwords($url[0]) . '.php')) {
// If exists, set as controller
$this->currentController = ucwords($url[0]);
// Unset 0 Index
unset($url[0]);
}
// Require the controller
require_once 'controllers/' . $this->currentController . '.php';
// Instantiate controller class
$this->currentController = new $this->currentController;
// Check for second part of url
if (isset($url[1])) {
// Check to see if method exists in controller
if (method_exists($this->currentController, $url[1])) {
$this->currentMethod = $url[1];
// Unset 1 index
unset($url[1]);
}
}
// Get params
$this->params = $url ? array_values($url) : [];
// Call a callback with array of params
call_user_func_array([$this->currentController, $this->currentMethod], $this->params);
}
public function getUrl()
{
if (isset($_GET['url'])) {
$url = rtrim($_GET['url'], '/');
$url = filter_var($url, FILTER_SANITIZE_URL);
$url = explode('/', $url);
return $url;
}
}
}