From 4b4c5271adf657331c867e79f88044d3317901ef Mon Sep 17 00:00:00 2001 From: Filipp Lepalaan Date: Fri, 27 May 2011 15:12:38 +0300 Subject: fixes --- MainApp.php | 26 ++++++++++++++------------ MainController.php | 17 +++++++++-------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/MainApp.php b/MainApp.php index 759a522..a74c6d4 100644 --- a/MainApp.php +++ b/MainApp.php @@ -11,7 +11,6 @@ * To Public License, Version 2, as published by Sam Hocevar. See * http://sam.zoy.org/wtfpl/COPYING for more details. */ - class MainApp { //// @@ -30,15 +29,15 @@ class MainApp if (strlen($param) < 1) { $action = self::conf('defaults.action'); } - + // fire up the output buffer ob_start(); - // dispatch correct controller + // dispatch requested controller $controller = self::classname($controller); - $c = new $controller; + $c = new $controller(); - // assume no method name was given, try $param, then default to defaultAction + // assume no method name was given, try $param // URL format is always controller/param/action if (method_exists($c, $action)) { return $c->$action($_POST); @@ -49,15 +48,16 @@ class MainApp return $c->$param($_POST); } - // controller/param + // ...then fall back to defaultAction if (method_exists($c, $c->defaultAction)) { $action = $c->defaultAction; return $c->$action($_POST); } - self::error("{$controller}/{$action}: no such method"); + // don't know what to do, giving up... + self::error("no such method: {$controller}/{$action}"); - // release the output buffer + // release the output buffer, normally this is done in render() ob_end_flush(); } @@ -65,13 +65,15 @@ class MainApp //// // requests should always be in the form: controller/action/parameters.type // Strip type info since it's not needed at this point - static function url($part = false) + static function url($part = FALSE) { $url = parse_url($_SERVER['REQUEST_URI']); - if ($part == 'query') { - return $url['query']; - } + if ($part == 'query') { + if (isset($url['query'])) { + return $url['query']; + } + } $req = ltrim($url['path'], '/'); $array = explode('/', preg_replace('/\.\w+$/', '', $req)); diff --git a/MainController.php b/MainController.php index c654ab0..de69e9a 100644 --- a/MainController.php +++ b/MainController.php @@ -14,26 +14,27 @@ class MainController { - public $view; // Where to store the data to be rendered - public $pageTitle = ''; // Title of the rendered page + public $view; // Where to store the data to be rendered + public $pageTitle = ''; // Title of the rendered page protected $template = 'default'; // The base template for this controller (view) - private $defaultAction = ''; // Method to run when none specified - const OrderBy = ''; // which column to order the results by + private $defaultAction = ''; // Method to run when none specified + + const OrderBy = ''; // which column to order the results by const HasMany = ''; const TableName = ''; const ManyToMany = ''; const ForeignKey = ''; const TableSelect = ''; // extra fields to select - public $data; - private $table; - private $primary_key; + public $data; // data returned from DB + private $table; // corresponding Db table + private $primary_key; // name of primary key column //// // create controller object - function __construct($where = null) + function __construct($where = NULL) { // child classes typically have the same name as their tables // but not always -- cgit v1.2.3