Initial Commit
This commit is contained in:
commit
138af6c355
21
.htaccess
Normal file
21
.htaccess
Normal file
@ -0,0 +1,21 @@
|
||||
IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*
|
||||
|
||||
<Limit GET POST>
|
||||
order deny,allow
|
||||
deny from all
|
||||
allow from all
|
||||
</Limit>
|
||||
<Limit PUT DELETE>
|
||||
order deny,allow
|
||||
deny from all
|
||||
</Limit>
|
||||
|
||||
<IfModule mod_rewrite.c>
|
||||
RewriteEngine On
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteCond %{REQUEST_FILENAME} !-d
|
||||
RewriteRule ^(.*)$ /index.php/$1 [L]
|
||||
</IfModule>
|
||||
<IfModule !mod_rewrite.c>
|
||||
ErrorDocument 404 /index.php
|
||||
</IfModule>
|
13
config.php
Normal file
13
config.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
// This is the controller that will be hit by default
|
||||
$default_controller = "welcome";
|
||||
|
||||
// Global Model Includes
|
||||
// These are Models that we ALWAYS want loaded
|
||||
$global_models = array();
|
||||
|
||||
// Global Library Includes
|
||||
// These are Libraries that we ALWAYS want loaded
|
||||
$global_libraries = array();
|
||||
|
9
controllers/welcome_controller.php
Normal file
9
controllers/welcome_controller.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
class Welcome_controller extends Controller {
|
||||
public function __construct() { }
|
||||
|
||||
public function index() {
|
||||
$this->load_views('welcome');
|
||||
}
|
||||
}
|
69
core/Controller.php
Normal file
69
core/Controller.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
class Controller {
|
||||
public function __construct() { }
|
||||
|
||||
public function load_model($model=NULL) {
|
||||
// All models end with '_model'
|
||||
if(is_array($model)) {
|
||||
foreach($model as $k=>$m) {
|
||||
$model[$k]=$m."_model";
|
||||
}
|
||||
} else {
|
||||
$model.="_model";
|
||||
}
|
||||
$this->_load_files($model, "models");
|
||||
}
|
||||
|
||||
public function load_library($library=NULL) {
|
||||
// All libraries end with '_library'
|
||||
if(is_array($library)) {
|
||||
foreach($library as $k=>$l) {
|
||||
$library[$k]=$l."_library";
|
||||
}
|
||||
} else {
|
||||
$library.="_library";
|
||||
}
|
||||
$this->_load_files($library, "libraries");
|
||||
}
|
||||
|
||||
public function load_view($views=NULL) {
|
||||
// No restrictions on view names
|
||||
$this->_load_files($views, "views", true);
|
||||
}
|
||||
|
||||
// Runs through a potential array of files
|
||||
// Checks for existence, then _load_file
|
||||
public function _load_files($a=null, $func=null, $multi=false) {
|
||||
if(isset($a) && isset($func)) {
|
||||
if(is_array($a)) {
|
||||
foreach($a as $aa) {
|
||||
if(defined('PHP_DIR')) {
|
||||
$f = PHP_DIR.$func."/".$aa.".php";
|
||||
} else {
|
||||
$f = $func."/".$aa.".php";
|
||||
}
|
||||
$this->_load_file($f, ($multi===true));
|
||||
}
|
||||
} else {
|
||||
if(defined('PHP_DIR')) {
|
||||
$f = PHP_DIR.$func."/".$a.".php";
|
||||
} else {
|
||||
$f = $func."/".$a.".php";
|
||||
}
|
||||
$this->_load_file($f, ($multi===true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Checks if the file exists and includes it
|
||||
public function _load_file($filename=NULL,$multi=false) {
|
||||
if(isset($filename) && file_exists($filename)) {
|
||||
if($multi) {
|
||||
include($filename);
|
||||
} else {
|
||||
require_once($filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
5
core/Model.php
Normal file
5
core/Model.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
class Model {
|
||||
public function __construct() { }
|
||||
}
|
41
core/uri_library.php
Normal file
41
core/uri_library.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
/* The URI Library is necessary for the framework
|
||||
* to succesfully route
|
||||
*/
|
||||
class Uri_library {
|
||||
private $uri_array = array();
|
||||
public function __construct($uri=NULL) {
|
||||
if(isset($uri)) {
|
||||
$this->parseURI($uri);
|
||||
}
|
||||
}
|
||||
|
||||
public function parseURI($uri=NULL) {
|
||||
if(substr($uri,0,10)=="/index.php") {
|
||||
$uri = substr($uri,10);
|
||||
}
|
||||
$uri=substr($uri,1);
|
||||
$this->uri_array = explode("/",$uri);
|
||||
}
|
||||
|
||||
public function getFullArray() {
|
||||
return $this->uri_array;
|
||||
}
|
||||
|
||||
public function getItem($iid=0) {
|
||||
if(isset($this->uri_array[$iid])) {
|
||||
return $this->uri_array[$iid];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function redirect($url=NULL) {
|
||||
if(isset($url)) {
|
||||
header('Location: '.$url);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
47
index.php
Normal file
47
index.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
require_once('config.php');
|
||||
|
||||
// We need the uri library for things to work
|
||||
$global_libraries[] = "uri";
|
||||
// Load up the base classes
|
||||
require_once('core/Controller.php');
|
||||
require_once('core/Model.php');
|
||||
require_once('core/uri_library.php');
|
||||
// Load up the globals
|
||||
foreach($global_libraries as $alib) {
|
||||
require_once('libraries/'.$alib.'_library.php');
|
||||
}
|
||||
foreach($global_models as $amod) {
|
||||
require_once('models/'.$amod.'_model.php');
|
||||
}
|
||||
|
||||
$uri = new Uri_library($_SERVER['REQUEST_URI']);
|
||||
$uri_array = $uri->getFullArray();
|
||||
// Check if $uri->getItem(0) is a controller
|
||||
if(file_exists('controllers/'.$uri_array[0].'_controller.php')) {
|
||||
// File exists, set the cc_name and pop the uri_array
|
||||
$class_name = array_shift($uri_array);
|
||||
$cc_name = $class_name."_controller";
|
||||
} else {
|
||||
// Not a valid controller, so hit the default
|
||||
$cc_name = $default_controller."_controller";
|
||||
}
|
||||
// Pull in the requested Controller
|
||||
require_once('controllers/'.$cc_name.'.php');
|
||||
|
||||
$c_class = new $cc_name;
|
||||
// Were we provided a method?
|
||||
$c_func = $uri_array[0];
|
||||
if($c_func!==false && method_exists($c_class, $c_func)) {
|
||||
$c_func = array_shift($uri_array);
|
||||
call_user_func_array(array($c_class, $c_func), $uri_array);
|
||||
} else {
|
||||
// Nope, hit the controller's index
|
||||
if(method_exists($c_class, 'index')) {
|
||||
call_user_func_array(array($c_class, "index"), $uri_array);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
20
views/welcome.php
Normal file
20
views/welcome.php
Normal file
@ -0,0 +1,20 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Welcome to the Anvil Framework</title>
|
||||
</head>
|
||||
<body style="text-align:left; padding-left:50px;">
|
||||
Welcome to the Anvil Framework!
|
||||
Everything is pretty self explanatory.
|
||||
<ul>
|
||||
<li>Controllers go in the controllers directory</li>
|
||||
<li>Models go in the models directory</li>
|
||||
<li>Views go in the views directory</li>
|
||||
<li>Libraries/Add-ons go in the libraries directory</li>
|
||||
</ul>
|
||||
Define your main controller in the config.php file.<br />
|
||||
That is the controller that will run if no other controller is specified.<br />
|
||||
<br />
|
||||
For more help, view the help
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user