From 36f3ac31483ebad37ebaa9625b91feff17560af2 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Fri, 30 Dec 2011 17:09:29 -0500 Subject: [PATCH] Updated readme and fixed some whitespace issues --- README.md | 28 ++- modules/welcome/models/welcome_model.php | 6 + sys/miniMVC.php | 232 ++++++++++++++--------- 3 files changed, 172 insertions(+), 94 deletions(-) create mode 100644 modules/welcome/models/welcome_model.php diff --git a/README.md b/README.md index c729ee5..b113ec2 100644 --- a/README.md +++ b/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. \ No newline at end of file diff --git a/modules/welcome/models/welcome_model.php b/modules/welcome/models/welcome_model.php new file mode 100644 index 0000000..d3f4e40 --- /dev/null +++ b/modules/welcome/models/welcome_model.php @@ -0,0 +1,6 @@ +$name)) - { - //Add $this object to args - array_push($args, $this); - - //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 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); + } + } + + /** + * 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); + } + } + /** * Prints out the contents of the object when used as a string @@ -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}"; - - if(class_exists($class, FALSE)) - { - if( ! isset($this->$name)) - { - $this->$name = new $class; - return; - } - } - - load_file($name, 'sys'); - + * 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; + } + } + + 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 = ""; - - // 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}/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)) + * 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)); + + $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 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 @@ -205,7 +207,53 @@ 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 \ No newline at end of file