Various Modifications

Move everything into App Directory
Add a SQLite Library
This commit is contained in:
2012-09-07 12:19:33 -05:00
parent 52b3f04ade
commit a371f1b0ff
11 changed files with 162 additions and 39 deletions

73
app/core/Controller.php Normal file
View File

@@ -0,0 +1,73 @@
<?php
class Controller {
public function __construct() { }
public function load_models($model=NULL) {
$this->load_model($model);
}
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_libraries($library=NULL) {
$this->load_library($library);
}
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_views($views=NULL, $vars=array()) {
$this->load_view($views,$vars);
}
public function load_view($views=NULL, $vars=array()) {
// No restrictions on view names
$this->_load_files($views, "views", true, $vars);
}
// Runs through a potential array of files
// Checks for existence, then _load_file
public function _load_files($a=null, $func=null, $multi=false, $vars=array()) {
if(isset($a) && isset($func)) {
if(is_array($a)) {
foreach($a as $aa) {
$f = APP_ROOT."/".$func."/".$aa.".php";
$this->_load_file($f, ($multi===true), $vars);
}
} else {
$f = APP_ROOT."/".$func."/".$a.".php";
$this->_load_file($f, ($multi===true), $vars);
}
}
}
// Checks if the file exists and includes it
public function _load_file($filename=NULL,$multi=false,$vars=null) {
if(isset($vars)&&is_array($vars)) {
extract($vars);
}
if(isset($filename) && file_exists($filename)) {
if($multi) {
include($filename);
} else {
require_once($filename);
}
}
}
}

5
app/core/Model.php Normal file
View File

@@ -0,0 +1,5 @@
<?php
class Model {
public function __construct() { }
}

41
app/core/uri_library.php Normal file
View 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);
}
}
}
?>