MarkMatute / mini_me

30kb PHP MVC Framework

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

mini_me

30kb PHP MVC Framework

A Very Light PHP MVC Framework, best to be used on small APIs.

Usage

You can access a certain controller via URL by defining the GET variable 'ctrl' [Stands for Controller]

and for the controller method, specify it to the GET variable 'act' [Stands for Action]

Creating a Controller

You can create a controller inside controllers directory, all controller must extends CONTROLLER Class.
Sample Controller

class TestCtrl extends Controller{
	private $Test_m;	

	public function __construct(){
		parent::__construct();
		
		// Load Realtime_m Model
		require_once(MODELS.'/Test_m.php');

		$this->Test_m = new Test_m();
	}
	
	function test(){
		$this->response['message'] = $this->Test_m->get_data();
		$this->return_json();
	}

}
  

Creating a Model

You can create a Model inside odels directory, all models must extends MODEL Class.
Sample Model

class Test_m extends Model{

	private $mysql; 

	public function __construct(){	
		parent::__construct();
		$this->mysql = $this->db->mysql();
	}

	public function get_data(){
		return array(
			'foo' => 'bar'
		);
	}
}
  

Connecting to Database

Connecting to a database is fairly easy.You can create database connections on core/database.php Ive tried to connect it to the ff databases:

  • MySQL
  • Postgre
  • MongoDB

Sample

Singleton Database Class

Uses PDO Driver

class Database {

# Instance of THIS class
private $_instance = NULL;

# Database Connection
private $_conn     = NULL;

# Constructor
public function __construct(){
	$this->_conn = new PDO('mysql:host=localhost;dbname=tester','root','');
}	

# Get Singleton Instance
public static function getInstance(){
	if(!self::$_instance){
		self::$_instance = new self();
	}
	return self::$_instance;
}		

# Hide Clone
private function __clone(){}

}

And you can access the database object via db object on Models, See model example.

# Feel Free to Comment or Suggest edits improvements, just drop an email markernest.matute@gmail.com

About

30kb PHP MVC Framework


Languages

Language:PHP 92.7%Language:ApacheConf 7.3%