Permalink
Browse files

Update

  • Loading branch information...
1 parent 648dc3f commit 5dc93fcf4b416228d6076dd2b0e72c1ed47b4f72 @atomicframeworks committed Jan 7, 2012
@@ -3,6 +3,7 @@
class Controller {
public $model;
public $data;
+ public $headersArray = array ();
public function __construct($args) {
if (!empty($args)){
@@ -24,8 +24,10 @@ function modelConnect($dbname = '', $user = 'root', $pass = '',$host = 'localhos
//echo "Connection to $dbname successful <br />";
}
catch(PDOException $e) {
- echo "Connection to $dbname failed <br />";
- echo $e->getMessage();
+ if (DEVELOPMENT_ENVIRONMENT === true) {
+ echo "Connection to $dbname failed <br />";
+ echo $e->getMessage();
+ }
}
//END DB connection try block
//Return $dbh if exists or false if error
@@ -15,7 +15,9 @@ public function __construct($args = array ()) {
}
}
// Connect to DB and get PDO handle
- $this->model = modelConnect($this->database,$this->username,$this->password,$this->host);
+ if (!empty($this->database)){
+ $this->model = modelConnect($this->database,$this->username,$this->password,$this->host);
+ }
}
//// Execute all statements in statementArray
@@ -65,7 +67,7 @@ public function fetchAll($fetchStyle = PDO::FETCH_CLASS){
$statementData = $statement->fetchAll($fetchStyle);
$statementString = $statement->queryString;
$returnArray = array ('data'=>$statementData,'statement'=>$statementString);
- array_push($return, $retAr);
+ array_push($return, $returnArray);
}
catch(PDOException $e) {
// Rollback changes to database on fail
@@ -1,7 +1,10 @@
<!--
-<?php header("Content-type: text/plain"); ?>
+<?php //header("Content-type: text/plain"); ?>
-->
+<?php
+ //print_r(get_defined_vars());
+?>
<html>
<body>
@@ -20,8 +23,8 @@
}
</style>
-
- <form method="get" action="./show">
+<?php echo $controller->database . DS . $controller->view;?>
+ <form method="get" action="../<?php echo $controller->database . DS ;?>show">
Query: <input type="text" size="100" maxlength="100" name="query" value='select INET_NTOA(ip) as ip, id, port, http_code, last_update from proxies where country = "China"'> <br />
<input type="submit" value="query">
</form>
View
@@ -71,30 +71,48 @@ function tQuote($val = ''){
//// Hook used to load our view and controller from url string
function callHook (){
+ // Default controller that will load if none is found
+ $controller_str = 'proxies';
+ //Default view that will load if none is found
+ $view_str = 'select';
// Get url query string
- $url = $_GET['url'];
- // Break to array based on directory separator
- $urlArray = explode(DIRECTORY_SEPARATOR, $url);
- // Separate controller & view strings from query
- $controller_str = $urlArray[0];
- $view_str = $urlArray[1];
+ if(!empty($_GET['url'])){
+ $url = $_GET['url'];
+ // Break to array based on directory separator
+ $urlArray = explode(DIRECTORY_SEPARATOR, $url);
+ // Separate controller & view strings from query
+ if (!empty($urlArray[0])){
+ $controller_str = $urlArray[0];
+ }
+ if (!empty($urlArray[1])){
+ $view_str = $urlArray[1];
+ }
+
+ }
+ else{
+ // On controller fail either create controller & set 404 or use default controller & views above
+ //$args = array('username' => DB_USERNAME, 'password' => DB_PASSWORD, 'database' => $controller_str, 'view'=>$view_str);
+ //$controller = new Controller($args);
+ //$controller->setHeader(404);
+ }
// Load files needed for controller & view
autoLoad($controller_str);
autoLoad($view_str);
// Create array to hold properties for controller
$args = array('username' => DB_USERNAME, 'password' => DB_PASSWORD, 'database' => $controller_str, 'view'=>$view_str);
- $controller = new Controller($args);
- $queryArray= explode('?query=',$_SERVER['REQUEST_URI']);
+ $controller = new Controller($args);
- // Perform query statements
+ // Perform query statements
+ $queryArray= explode('?query=',$_SERVER['REQUEST_URI']);
if(!empty($queryArray[1])){
$queryString = $queryArray[1];
$queryString = urldecode(tQuote($queryString));
//echo "<br/> Query: $queryString <br/>";
$controller->addStatement($queryString)->invoke()->fetchAll();
- }
+ }
+
// Load our view
$controller->displayView();
}

0 comments on commit 5dc93fc

Please sign in to comment.