Various Modifications
Move everything into App Directory Add a SQLite Library
This commit is contained in:
18
app/config.php
Normal file
18
app/config.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?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();
|
||||
|
||||
// This tells the system to throw away the first URI token
|
||||
// For example, if the system is kept in:
|
||||
// http://mysite.com/folder1/
|
||||
// Then setting this should be set to 1
|
||||
$starting_token = 0;
|
9
app/controllers/welcome_controller.php
Normal file
9
app/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');
|
||||
}
|
||||
}
|
73
app/core/Controller.php
Normal file
73
app/core/Controller.php
Normal 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
5
app/core/Model.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
class Model {
|
||||
public function __construct() { }
|
||||
}
|
41
app/core/uri_library.php
Normal file
41
app/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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
0
app/libraries/.gitignore
vendored
Normal file
0
app/libraries/.gitignore
vendored
Normal file
96
app/libraries/sqlite_library.php
Normal file
96
app/libraries/sqlite_library.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
class Anvil_SQLite {
|
||||
private $handle;
|
||||
private $db_file_name;
|
||||
private $config_db_name = "/db/my_db.sqlite";
|
||||
|
||||
private $sel_cols = array();
|
||||
private $where_arr = array();
|
||||
|
||||
private $result;
|
||||
|
||||
function __construct($no_open=FALSE) {
|
||||
if($no_open===FALSE) {
|
||||
$this->open_db();
|
||||
}
|
||||
}
|
||||
|
||||
function open_db() {
|
||||
$this->db_file_name = APP_ROOT.$this->config_db_name;
|
||||
$this->handle = new SQLite3($this->db_file_name);
|
||||
}
|
||||
|
||||
function query($query, $escape=TRUE) {
|
||||
$do_query = ($escape===TRUE)?$this->handle->escapeString($query):$query;
|
||||
$this->result = $this->handle->query($do_query);
|
||||
return $this->result;
|
||||
}
|
||||
|
||||
function select($colnames) {
|
||||
$colnames=(is_array($colnames)?$colnames:array($colnames));
|
||||
$this->sel_cols = $colnames;
|
||||
}
|
||||
|
||||
function where(array $where_arr) {
|
||||
$this->where_arr = $where_arr;
|
||||
}
|
||||
|
||||
function get($tablename) {
|
||||
// Build the 'SELECT' part of the query
|
||||
$select_q= "SELECT ";
|
||||
$num_sel_cols = count($this->sel_cols);
|
||||
if($num_sel_cols == 0) {
|
||||
$select_q.="* ";
|
||||
} else {
|
||||
foreach($this->sel_cols as $a_col) {
|
||||
$select_q.=$a_col;
|
||||
if(--$num_sel_cols > 0)
|
||||
$select_q.=", ";
|
||||
}
|
||||
}
|
||||
// Build the 'FROM' part of the query
|
||||
$from_q = "FROM ".$tablename." ";
|
||||
// Build the 'WHERE' part of the query
|
||||
$where_q = "";
|
||||
$num_where_arr = count($this->where_arr);
|
||||
if($num_where_arr > 0) {
|
||||
$where_q = "WHERE ";
|
||||
foreach($this->where_arr as $a_col => $a_where) {
|
||||
$where_q.=$a_col." = '".$a_where."' ";
|
||||
if(--$num_where_arr > 0)
|
||||
$where_q.="AND ";
|
||||
}
|
||||
}
|
||||
return $this->query($select_q.$from_q.$where_q);
|
||||
}
|
||||
|
||||
function fetch_array($res=NULL) {
|
||||
$res=(isset($res)?$res:$this->result);
|
||||
$i = 0;
|
||||
while($resx = $res->fetchArray(SQLITE3_ASSOC)) {
|
||||
$ret_arr[] = $resx;
|
||||
}
|
||||
return $ret_arr;
|
||||
}
|
||||
|
||||
function insert($tablename, array $val_arr) {
|
||||
$ins_q = "INSERT INTO ".$tablename;
|
||||
$num_cols = count($val_arr);
|
||||
if($num_cols <= 0) { return false; }
|
||||
|
||||
$ins_col1 = "(";
|
||||
$ins_col2 = " VALUES (";
|
||||
foreach($val_arr as $col_n => $val) {
|
||||
$ins_col1 .= $col_n;
|
||||
$ins_col2 .= "\"".$val."\"";
|
||||
if(--$num_cols > 0) {
|
||||
$ins_col1 .= ", ";
|
||||
$ins_col2 .= ", ";
|
||||
}
|
||||
}
|
||||
$ins_col1 .= ")";
|
||||
$ins_col2 .= ")";
|
||||
return $this->query($ins_q.$ins_col1.$ins_col2);
|
||||
}
|
||||
}
|
0
app/models/.gitignore
vendored
Normal file
0
app/models/.gitignore
vendored
Normal file
52
app/views/welcome.php
Normal file
52
app/views/welcome.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Welcome to the Anvil Framework</title>
|
||||
<style type="text/css">
|
||||
body {
|
||||
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
|
||||
font-size: 14px;
|
||||
color: #333;
|
||||
}
|
||||
.welcome_div {
|
||||
position:relative;
|
||||
margin:15px 0;
|
||||
padding:39px 19px 14px;
|
||||
background-color:#FFF;
|
||||
border:1px solid #DDD;
|
||||
-webkit-border-radius: 4px;
|
||||
-moz-border-radius: 4px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
.welcome_div::after {
|
||||
content: "Anvil_PHP";
|
||||
position: absolute;
|
||||
top: -1px;
|
||||
left: -1px;
|
||||
padding:3px 7px;
|
||||
font-size: 12px;
|
||||
font-weight: bold;
|
||||
background-color: whiteSmoke;
|
||||
border: 1px solid #DDD;
|
||||
color: #9DA0A4;
|
||||
-webkit-border-radius: 4px 0 4px 0;
|
||||
-moz-border-radius: 4px 0 4px 0;
|
||||
border-radius: 4px 0 4px 0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body style="text-align:left; padding-left:50px;">
|
||||
<div class="welcome_div">
|
||||
Welcome to the Anvil Framework!
|
||||
<ul>
|
||||
<li>Controllers go in the app/controllers directory</li>
|
||||
<li>Models go in the app/models directory</li>
|
||||
<li>Views go in the app/views directory</li>
|
||||
<li>Libraries/Add-ons go in the app/libraries directory</li>
|
||||
</ul>
|
||||
<p>If you place the Application Root anywhere other than the default, then you need to change the "APP_ROOT" constant in index.php</p>
|
||||
<p>Next, define your main controller in the config.php file</p>
|
||||
<p>That is the controller that will run if no other controller is specified.</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user