aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--MainApp.php34
-rw-r--r--MainController.php27
-rw-r--r--MainDb.php1
-rw-r--r--MainView.php1
-rw-r--r--README.md4
5 files changed, 38 insertions, 29 deletions
diff --git a/MainApp.php b/MainApp.php
index 8ab3a94..ac58db5 100644
--- a/MainApp.php
+++ b/MainApp.php
@@ -11,6 +11,7 @@
* To Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details.
*/
+
class MainApp
{
////
@@ -24,7 +25,7 @@ class MainApp
if (!$controller) {
$controller = self::conf('defaults.controller');
}
-
+
// no action given, read default one
if (strlen($param) < 1) {
$action = self::conf('defaults.action');
@@ -36,9 +37,9 @@ class MainApp
// dispatch correct controller
$controller = self::classname($controller);
$c = new $controller;
-
+
// assume no method name was given, try $param, then default to defaultAction
- // controller/param/action
+ // URL format is always controller/param/action
if (method_exists($c, $action)) {
return $c->$action($_POST);
}
@@ -99,7 +100,7 @@ class MainApp
if (!file_exists($cpath)) {
trigger_error('Failed to open config file', E_USER_ERROR);
- return false;
+ return FALSE;
}
$config = parse_ini_file($cpath, true);
@@ -343,18 +344,19 @@ class MainApp
}
}
-
- ////
- // for autoloading the app's classes
- function __autoload($name)
- {
- $class_name = MainApp::classname($name);
- include_once "{$class_name}.php";
+
+////
+// for autoloading the app's classes
+function __autoload($name)
+{
+ $class_name = MainApp::classname($name);
+
+ include_once "{$class_name}.php";
- if (!class_exists($class_name)) {
- exit(MainApp::error("{$class_name}: no such class"));
- }
-
+ if (!class_exists($class_name)) {
+ exit(MainApp::error("{$class_name}: no such class"));
}
+
+}
-?> \ No newline at end of file
+?>
diff --git a/MainController.php b/MainController.php
index 381e1c1..da27b81 100644
--- a/MainController.php
+++ b/MainController.php
@@ -11,6 +11,7 @@
* To Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details.
*/
+
class MainController
{
public $view; // Where to store the data to be rendered
@@ -18,8 +19,8 @@ class MainController
public $defaultAction = ''; // Method to run when none specified
- const OrderBy = '';
- const HasMany = '';
+ const OrderBy = ''; // which column to order the results by
+ const HasMany = '';
const TableName = '';
const ManyToMany = '';
const ForeignKey = '';
@@ -81,22 +82,26 @@ class MainController
public function init()
{
// populate indices
- if ($_SESSION['config']['db.driver'] == 'mysql') {
- $schema = MainDb::fetch('DESCRIBE `'.$this->table.'`');
- foreach ($schema as $s) {
- $this->data[$s['Field']] = $s['Default'];
- }
- return $this;
- }
+ $driver = MainApp::conf('db.driver');
- if ($_SESSION['config']['db.driver'] == 'sqlite') {
+ switch ($driver) {
+ case 'sqlite':
$sql = 'PRAGMA TABLE_INFO('.$this->table.')';
$schema = MainDb::fetch($sql);
foreach ($schema as $s) {
$this->data[$s['name']] = '';
}
- }
return $this;
+ break;
+
+ default:
+ $schema = MainDb::fetch('DESCRIBE `'.$this->table.'`');
+ foreach ($schema as $s) {
+ $this->data[$s['Field']] = $s['Default'];
+ }
+ return $this;
+ break;
+ }
}
////
diff --git a/MainDb.php b/MainDb.php
index 589ce82..06263a0 100644
--- a/MainDb.php
+++ b/MainDb.php
@@ -12,6 +12,7 @@
* To Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details.
*/
+
class MainDb
{
private static $instance = NULL;
diff --git a/MainView.php b/MainView.php
index 444dceb..edfc6e4 100644
--- a/MainView.php
+++ b/MainView.php
@@ -11,6 +11,7 @@
* To Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details.
*/
+
class MainView
{
////
diff --git a/README.md b/README.md
index c881fea..c4abea1 100644
--- a/README.md
+++ b/README.md
@@ -16,8 +16,8 @@ MAIN - the simple PHP framework
So a typical bootstrap would go something like this:
cd mysite
- mkdir system/lib data public system
- touch public/index.php data/error.log
+ mkdir -p system data public system/lib system/classes system/views
+ touch public/index.php data/error.log views/default.html
cd system/lib
git clone git://github.com/filipp/main.git
cd ../..