Fork me on GitHub

Orc.

A PHP based micro MVC framework.MIT License

Installing

Orc can be used directly by simply putting the bundle in your www , however there is requirement of mod_rewrite Apache module.

Downloading

							git clone https://github.com/flouthoc/orc.git
						
Simply clone the latest Orc from github repository

Supported Database Systems

By default system supports php handle for mysqli but every possible database system can be added to Orc by creating a OO handle for respective Database system in ../application/db.class.php, it would be great if you'll put handle for your DB engine here.


Understanding Orc

Conceptually

MVC Wikipedia

Implementaion and code

Most of the working concept of Orc is quit analoguous to CodeIgniter Web Framework. A basic layout is totally from Kevin Waterson's MVC tutorial and I'll try to discuss concept behind all new code in comments and documentation.

Documentation

Url Routing

Url Routing is integral part of framework , to make it work as a Single Entry point MVC and route the content throught the controller and models a router is essential to grasp which controller is requested ? , which action is called ? What are the arguments given to action ?.All the code related to routing is written inside ../application/router.class.php and it goes like this.

Url in raw form
							http://domain.com/controller.php?rt=action/there/goes/arguments/
						
  • controller.php - Points to the controller class which extends Base Controller
  • action - action is method inside controllerclass which accepts arguments to be processed by Model or Controller itself.
  • arguments - after supplying arguments behind the wheel it looks like this $controller->action($argument_array); now you can process the given input
Shazam!!! now mod_rewrite plays with it and it can look like this
								http://domain.com/controller/action/there/goes/arguments/
							

Controllers and Custom Controllers

Controllers

Major Part of the framework will be constructed of controllers and custom controllers.Controllers are something which are responsible for taking response from User and processing them accordingly to give Model appropriate data to process the Bussiness Logic from there the Data is retrived by Views and that's how the cycle rolls.

Controllers calls the Model by using some of the methods , we are going to call them actions. Each Controller have many actions to proceed giving arguments to be processed by Model.So we can assume action like this.

							/**This is not how i'll look in code , this is just to give you rough image **/
$controllerInstance->action($argumentarray);
/** similarly action() makes a call to model **/
						

Custom Controllers

Every custom controller must be saved in /controller/ and should extend or inherit ../application/controllerBase.class.php every controller must contain a action index which will be called if in argument no controller has been given.
Example
Class indexController Extends baseController {

	public function index() {
		/*** set a template variable ***/
        $this->registry->template->welcome = $this->model->welcome;

		/*** load the index template and get file from VIEW ***/
        $this->registry->template->show('index');
	}


	/* A test function to check weather we can recieve arguments via url or not */

	public function poop($array){

		var_dump($array);

	}

	public function some_random_action_which_calls_model($argumentarray){

		/** Do some random operation on welcome by taking argument **/
		$this->model->somemethod($argumentarray);

		$this->registry->template->welcome = $this->model->welcome;

		/*** load the index template and get file from VIEW ***/
        	$this->registry->template->show('index');
	}

}

Views

Templates

Views are basically a HTML skeleton , or HTML layout which can contain PHP based template variables to load dynamic content inside these variables and these variables must be attribute of instance of template class which is to be stored in $registry (object of registry class) and these Template Variables can be manipulated in any action of the respective controller of View.

<html>

	<head>
	</head>

	<body>
		<h1><?php echo $welcome; ?></h1>
		<p><?php echo $blogContent ?></p>
	</body>

</html>  
					Using Template Variables with custom Controllers
									

Class indexController Extends baseController {

	public function index() {

		/*** setting template variables a template variables ***/

        $this->registry->template->welcome = "Welcome User";
        $this->registry->template->blogContent = "Here goes your blog content";

		/*** load the index template or name of view ***/

        $this->registry->template->show('index');
	}


}


					

Models

Models are something which contain Business Logic and it is to be noted that every can only be called from controller of that model. Model can contain many methods and these methods can take argument from Controller methods and can update the template variables further. Every model must be stored in ../model/ with name convention like this 'name'Model.class.php

class indexModel{

	public $welcome = "Welcome to blog";
	public $blogContent;

	public getBlogContent(){

		$this->blogContent = make_database_call();
	}
}


					

Using Database with Models

Inside ../application/ there is a class named db.class.php you can use object of this class to get the mysqli handle you can use it like this.

$dbinstance = new db("mysql","host","user","passwd","database");

/*Now you can use $handle attribute of this object to call mysqli method*/
$dbinstance->handle->query("SELECT * FROM foo");

/*you can also store this inside registry so that you can get this upto MODEL*/
$registry->db = $dbinstance;



					

Contributing - ToDo's

  • Add your database handler to application/db.class.php
  • Add a test directory with test cases inside
  • Improve Docs
  • Add plugins

Fork it / Create Pull

Github - Link
Email - flouthoc@gmail.com