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);
|
||||
}
|
||||
|
||||
/**
|
||||
* PHP magic method to facilitate dynamic methods
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $args
|
||||
*/
|
||||
function __call($name, $args)
|
||||
{
|
||||
if(is_callable(self::$instance->$name))
|
||||
{
|
||||
//Add $this object to args
|
||||
array_push($args, $this);
|
||||
/**
|
||||
* PHP magic method to facilitate dynamic methods
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $args
|
||||
*/
|
||||
function __call($name, $args)
|
||||
{
|
||||
if(is_callable(self::$instance->$name))
|
||||
{
|
||||
//Add $this object to args
|
||||
array_push($args, $this);
|
||||
|
||||
//Call the dynamic function
|
||||
return call_user_func_array(self::$instance->$name, $args);
|
||||
}
|
||||
}
|
||||
//Call the dynamic function
|
||||
return call_user_func_array(self::$instance->$name, $args);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* PHP magic method to facilitate dynamically set static methods
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $args
|
||||
*/
|
||||
public static function __callStatic($name, $args)
|
||||
{
|
||||
if(is_callable(self::$name))
|
||||
{
|
||||
return call_user_func_array(self::$name, $args);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* PHP magic method to facilitate dynamically set static methods
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $args
|
||||
*/
|
||||
public static function __callStatic($name, $args)
|
||||
{
|
||||
if(is_callable(self::$name))
|
||||
{
|
||||
return call_user_func_array(self::$name, $args);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -109,41 +109,43 @@ class miniMVC{
|
||||
}
|
||||
|
||||
/**
|
||||
* PHP magic method to facilitate dynamic class loading
|
||||
*
|
||||
* @param string $name
|
||||
*/
|
||||
function __get($name)
|
||||
{
|
||||
$path = SYS_PATH."{$name}.php";
|
||||
$class = "{$name}";
|
||||
* PHP magic method to facilitate dynamic class loading
|
||||
*
|
||||
* @param string $name
|
||||
*/
|
||||
function __get($name)
|
||||
{
|
||||
$path = SYS_PATH."{$name}.php";
|
||||
$class = "{$name}";
|
||||
|
||||
if(class_exists($class, FALSE))
|
||||
{
|
||||
if( ! isset($this->$name))
|
||||
{
|
||||
$this->$name = new $class;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(class_exists($class, FALSE))
|
||||
{
|
||||
if( ! isset($this->$name))
|
||||
{
|
||||
$this->$name = new $class;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
load_file($name, 'sys');
|
||||
load_file($name, 'sys');
|
||||
|
||||
if(class_exists($class, FALSE))
|
||||
{
|
||||
$this->$name = new $class;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* PHP magic method that is called when an object is treated as a function
|
||||
*/
|
||||
public static function __invoke()
|
||||
{
|
||||
return self::get_instance();
|
||||
}
|
||||
/**
|
||||
* PHP magic method that is called when an object is treated as a function
|
||||
*/
|
||||
public static function __invoke()
|
||||
{
|
||||
return self::get_instance();
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
class MM_Controller extends miniMVC {
|
||||
|
||||
function __construct()
|
||||
@ -155,37 +157,37 @@ class MM_Controller extends miniMVC {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function for loading a view
|
||||
*
|
||||
* @param string $file
|
||||
* @param array $data
|
||||
* @return mixed
|
||||
*/
|
||||
function load_view($file, $data, $return=FALSE)
|
||||
{
|
||||
$path = "";
|
||||
* Function for loading a view
|
||||
*
|
||||
* @param string $file
|
||||
* @param array $data
|
||||
* @return mixed
|
||||
*/
|
||||
function load_view($file, $data, $return=FALSE)
|
||||
{
|
||||
$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));
|
||||
// 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');
|
||||
$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}/views/{$file}.php";
|
||||
}
|
||||
// If it's a module, look in the module view folder
|
||||
if( ! in_array($module, $not_modules))
|
||||
{
|
||||
$path = MOD_PATH . "{$module}/views/{$file}.php";
|
||||
}
|
||||
|
||||
// If it's not a module, or doesn't exist in the module view folder
|
||||
// look in the app view folder
|
||||
if( ! is_file($path))
|
||||
// If it's not a module, or doesn't exist in the module view folder
|
||||
// look in the app view folder
|
||||
if( ! is_file($path))
|
||||
{
|
||||
$path = APP_PATH . "views/{$file}.php";
|
||||
}
|
||||
|
||||
// Contain the content for buffering
|
||||
// Contain the content for buffering
|
||||
ob_start();
|
||||
|
||||
// Extract the data array
|
||||
@ -206,6 +208,52 @@ class MM_Controller extends miniMVC {
|
||||
$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
|
Loading…
Reference in New Issue
Block a user