Go to file
Timothy Warren a8cbfb0cbe miscellaneous tweaks 2012-05-15 16:53:10 -04:00
app Miscellaneous improvements 2012-05-14 14:35:57 -04:00
assets Miscellaneous improvements 2012-05-14 14:35:57 -04:00
docs miscellaneous tweaks 2012-05-15 16:53:10 -04:00
sys miscellaneous tweaks 2012-05-15 16:53:10 -04:00
tests Miscellaneous improvements 2012-05-14 14:35:57 -04:00
.gitmodules Remove extra files 2012-05-14 14:52:01 -04:00
README.md Update readme 2012-05-15 10:27:34 -04:00
index.php miscellaneous tweaks 2012-05-15 16:53:10 -04:00
phpdoc.dist.xml Remove query docs from generated documentation 2012-05-15 12:40:32 -04:00

README.md

miniMVC

miniMVC is a minimalistic Modular MVC framework, with built-in minifier, and pure-PHP templating system.

Requirements

  • PHP 5.4+
  • PDO extensions for databases you wish to use
  • Webserver that correctly handles REQUEST_URI, such as:
    • Apache
    • IIS
    • Lighttpd
  • SimpleTest library for running unit tests

Unique features

Extensive use of PHP's magic methods on the base class

  • __toString() method allows a view of the current class object when the current class object is used as a string. If you prefer var_dump() or var_export(), you can pass the name of that function if you call the __toString method directly.

    Eg. $this . "string", $this->__toString(), echo $this;

  • __call() method allows the dynamic addition of callable closure objects

    Eg. $this->foo = function($baz){} is callable as $this->foo(), with the current object as the last argument

  • MM class extends ArrayObject, and all the main classes extend this class. Functions begining with array_ are callable on object from this class. E.g. $this->array_keys() will return a list of the class properties.

Database class is an extension of PHP's PDO class.

Database class uses Query as a database abstraction layer and query builder.

Database connections are set in /app/config/db.php

File Structure

  • index.php - framework bootstrap

  • app - configuration and app-wide files

    • classes - helper classes
    • config - configuration files
    • modules - MVC triads
      • controllers - controller classes
      • models - model classes
      • views - module-specific views
    • views - global page templates
      • errors - error page templates
  • assets - frontend files

    • js - javascript files
    • css - css files
    • config - minifier configuration files
  • sys - core framework classes

Common Tasks

  • Creating a controller

      <?php 
      class Foo extends MM_Controller {
    
      	function __construct()
      	{
      		parent::__construct();
      	}
      }
    
  • Creating a model

      <?php
      class Bar extends MM_Model {
    
      	function __construct()
      	{
      		parent::__construct();
      	}
      }
    
  • Loading a database

    $this->db = db::get_instance($db_name);

    Note that multiple databases can be used in the same class by specifying a different database name.

  • Loading a model (From a controller)

    $this->load_model($model) - creates an instance of that model as a member of the current class. After loading the model, you can call its methods like so

    $this->[model name]->method()

  • Loading a class

    Load a system library, or a custom library from the app/classes folder.

    $this->load_class($class) - creates an instance of that class as a member of the current class. After loading the class, you can call its methods like so

    $this->[class name]->method()