Updated readme and fixed some whitespace issues
This commit is contained in:
parent
a72f8d332f
commit
36f3ac3148
28
README.md
28
README.md
@ -1,3 +1,27 @@
|
|||||||
miniMVC is a php framework based on javascript-like objects.
|
# miniMVC
|
||||||
|
|
||||||
|
miniMVC is a minimalistic Modular MVC framework, with built-in minifier, and pure-PHP templating system.
|
||||||
|
|
||||||
|
It has the following file structure
|
||||||
|
|
||||||
|
*index.php* - framework frontend
|
||||||
|
|
||||||
|
*app* - configuration and app-wide files
|
||||||
|
*config* - configuration files
|
||||||
|
*errors* - error page templates
|
||||||
|
*views* - global page templates
|
||||||
|
|
||||||
|
*assets* - frontend files
|
||||||
|
*js* - javascript files
|
||||||
|
*css* - css files
|
||||||
|
*config* - minifier configuration files
|
||||||
|
|
||||||
|
*modules* - MVC triads
|
||||||
|
*controllers* - controller classes
|
||||||
|
*models* - model classes
|
||||||
|
*views* - module-specific views
|
||||||
|
|
||||||
|
*sys* - core framework classes
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
It is currently pre-alpha. Features are still being built-out.
|
|
6
modules/welcome/models/welcome_model.php
Normal file
6
modules/welcome/models/welcome_model.php
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Welcome_Model {
|
||||||
|
|
||||||
|
function __construct(){}
|
||||||
|
}
|
204
sys/miniMVC.php
204
sys/miniMVC.php
@ -41,37 +41,37 @@ class miniMVC{
|
|||||||
trigger_error('Clone is not allowed.', E_USER_ERROR);
|
trigger_error('Clone is not allowed.', E_USER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PHP magic method to facilitate dynamic methods
|
* PHP magic method to facilitate dynamic methods
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param array $args
|
* @param array $args
|
||||||
*/
|
*/
|
||||||
function __call($name, $args)
|
function __call($name, $args)
|
||||||
{
|
{
|
||||||
if(is_callable(self::$instance->$name))
|
if(is_callable(self::$instance->$name))
|
||||||
{
|
{
|
||||||
//Add $this object to args
|
//Add $this object to args
|
||||||
array_push($args, $this);
|
array_push($args, $this);
|
||||||
|
|
||||||
//Call the dynamic function
|
//Call the dynamic function
|
||||||
return call_user_func_array(self::$instance->$name, $args);
|
return call_user_func_array(self::$instance->$name, $args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PHP magic method to facilitate dynamically set static methods
|
* PHP magic method to facilitate dynamically set static methods
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param array $args
|
* @param array $args
|
||||||
*/
|
*/
|
||||||
public static function __callStatic($name, $args)
|
public static function __callStatic($name, $args)
|
||||||
{
|
{
|
||||||
if(is_callable(self::$name))
|
if(is_callable(self::$name))
|
||||||
{
|
{
|
||||||
return call_user_func_array(self::$name, $args);
|
return call_user_func_array(self::$name, $args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -109,41 +109,43 @@ class miniMVC{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PHP magic method to facilitate dynamic class loading
|
* PHP magic method to facilitate dynamic class loading
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
*/
|
*/
|
||||||
function __get($name)
|
function __get($name)
|
||||||
{
|
{
|
||||||
$path = SYS_PATH."{$name}.php";
|
$path = SYS_PATH."{$name}.php";
|
||||||
$class = "{$name}";
|
$class = "{$name}";
|
||||||
|
|
||||||
if(class_exists($class, FALSE))
|
if(class_exists($class, FALSE))
|
||||||
{
|
{
|
||||||
if( ! isset($this->$name))
|
if( ! isset($this->$name))
|
||||||
{
|
{
|
||||||
$this->$name = new $class;
|
$this->$name = new $class;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
load_file($name, 'sys');
|
load_file($name, 'sys');
|
||||||
|
|
||||||
if(class_exists($class, FALSE))
|
if(class_exists($class, FALSE))
|
||||||
{
|
{
|
||||||
$this->$name = new $class;
|
$this->$name = new $class;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PHP magic method that is called when an object is treated as a function
|
* PHP magic method that is called when an object is treated as a function
|
||||||
*/
|
*/
|
||||||
public static function __invoke()
|
public static function __invoke()
|
||||||
{
|
{
|
||||||
return self::get_instance();
|
return self::get_instance();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
class MM_Controller extends miniMVC {
|
class MM_Controller extends miniMVC {
|
||||||
|
|
||||||
function __construct()
|
function __construct()
|
||||||
@ -155,37 +157,37 @@ class MM_Controller extends miniMVC {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function for loading a view
|
* Function for loading a view
|
||||||
*
|
*
|
||||||
* @param string $file
|
* @param string $file
|
||||||
* @param array $data
|
* @param array $data
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function load_view($file, $data, $return=FALSE)
|
function load_view($file, $data, $return=FALSE)
|
||||||
{
|
{
|
||||||
$path = "";
|
$path = "";
|
||||||
|
|
||||||
// The module is the lower of the class name
|
// The module is the lower of the class name
|
||||||
// need to figure out a way to allow multiple controllers
|
// need to figure out a way to allow multiple controllers
|
||||||
// in one module
|
// in one module
|
||||||
$module = strtolower(get_class($this));
|
$module = strtolower(get_class($this));
|
||||||
|
|
||||||
$not_modules = array('miniMVC', 'page', 'db', 'output');
|
$not_modules = array('miniMVC', 'page', 'db', 'output');
|
||||||
|
|
||||||
// If it's a module, look in the module view folder
|
// If it's a module, look in the module view folder
|
||||||
if( ! in_array($module, $not_modules))
|
if( ! in_array($module, $not_modules))
|
||||||
{
|
{
|
||||||
$path = MOD_PATH . "{$module}/views/{$file}.php";
|
$path = MOD_PATH . "{$module}/views/{$file}.php";
|
||||||
}
|
}
|
||||||
|
|
||||||
// If it's not a module, or doesn't exist in the module view folder
|
// If it's not a module, or doesn't exist in the module view folder
|
||||||
// look in the app view folder
|
// look in the app view folder
|
||||||
if( ! is_file($path))
|
if( ! is_file($path))
|
||||||
{
|
{
|
||||||
$path = APP_PATH . "views/{$file}.php";
|
$path = APP_PATH . "views/{$file}.php";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Contain the content for buffering
|
// Contain the content for buffering
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
// Extract the data array
|
// Extract the data array
|
||||||
@ -206,6 +208,52 @@ class MM_Controller extends miniMVC {
|
|||||||
$this->output->append_output($buffer);
|
$this->output->append_output($buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function for loading a model into the current controller
|
||||||
|
*
|
||||||
|
* @param string $file
|
||||||
|
*/
|
||||||
|
function load_model($file)
|
||||||
|
{
|
||||||
|
$path = "";
|
||||||
|
|
||||||
|
// The module is the lower of the class name
|
||||||
|
// need to figure out a way to allow multiple controllers
|
||||||
|
// in one module
|
||||||
|
$module = strtolower(get_class($this));
|
||||||
|
|
||||||
|
$not_modules = array('miniMVC', 'page', 'db', 'output');
|
||||||
|
|
||||||
|
// If it's a module, look in the module view folder
|
||||||
|
if( ! in_array($module, $not_modules))
|
||||||
|
{
|
||||||
|
$path = MOD_PATH . "{$module}/models/{$file}.php";
|
||||||
|
}
|
||||||
|
|
||||||
|
require_once($path);
|
||||||
|
|
||||||
|
$this->$file = new $file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class MM_Model extends miniMVC {
|
||||||
|
|
||||||
|
function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the database class to the current model class
|
||||||
|
*/
|
||||||
|
function load_db($name)
|
||||||
|
{
|
||||||
|
$this->db = new db($name);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// End of miniMVC.php
|
// End of miniMVC.php
|
Loading…
Reference in New Issue
Block a user