diff --git a/index.php b/index.php index 91f3fd9..a20535c 100644 --- a/index.php +++ b/index.php @@ -9,9 +9,9 @@ define('MOD_PATH', __DIR__.'/modules/'); define('APP_PATH', __DIR__.'/app/'); $ri = $_SERVER['REQUEST_URI']; -$ind_pos = stripos($ri, "index.php/"); +$ind_pos = stripos($ri, "index.php"); $default_path = ($ind_pos !== FALSE) ? substr($ri, 0, $ind_pos) : $ri; -$default_baseurl = "//".$_SERVER['HTTP_HOST']. $default_path; +$default_baseurl = "//" . str_replace("//", "/", $_SERVER['HTTP_HOST']. $default_path); // Require the basic configuratio file require(APP_PATH.'config/config.php'); diff --git a/modules/welcome/controllers/welcome.php b/modules/welcome/controllers/welcome.php index 93362af..247f0fe 100644 --- a/modules/welcome/controllers/welcome.php +++ b/modules/welcome/controllers/welcome.php @@ -10,7 +10,8 @@ class Welcome extends MM_Controller { function index() { - $this->page->output_string($this->page->set_message('info', "This is just a test message", TRUE)); + $output = $this->page->set_message('info', "This is just a test message", TRUE); + $this->page->output_string($output); } function php() diff --git a/sys/common.php b/sys/common.php index f3231a1..b556d39 100644 --- a/sys/common.php +++ b/sys/common.php @@ -126,6 +126,45 @@ function show_error() // -------------------------------------------------------------------------- +/** + * Returns routable methods for the specified controller class + * + * @param string $controller + * @return array + */ +function controller_methods($controller) +{ + $methods = get_class_methods($controller); + $num = count($methods); + + for($i=0; $i < $num; $i++) + { + $skip_methods = array( + 'load_file', + 'on_error', + 'on_exception', + 'show_404', + 'show_error', + 'controller_methods', + 'route', + 'site_url', + 'load_view', + 'get_instance', + ); + + // If the method starts with an underscore, or + // is in the blacklist of methods, it is not callable + if($methods[$i]{0} === "_" || in_array($methods[$i], $skip_methods)) + { + unset($methods[$i]); + } + } + + return $methods; +} + +// -------------------------------------------------------------------------- + /** * Calls the appropriate module/controller/function based on the url */ @@ -141,8 +180,8 @@ function route() $controller = $routes['default_controller']; $func = "index"; $route_set = FALSE; - - + + // If it isn't the index page if( ! empty($pi) && $pi !== "/") { //Remove trailing slash and begining slash @@ -178,7 +217,9 @@ function route() // Match on module/controller/method, controller/method, or method if( ! $route_set) { - if(strpos($pi, '/') === FALSE) + $num_segments = 0; + + if(strpos($pi, '/') === FALSE && ! empty($pi)) { $num_segments = 1; } @@ -188,7 +229,6 @@ function route() $num_segments = count($segments); } - if($num_segments === 1) { $func = $pi; @@ -212,17 +252,23 @@ function route() { require_once($path); - $methods = get_class_methods($controller); + // Get the list of valid methods for that controller + $methods = controller_methods($controller); if(in_array($func, $methods)) { $class = new $controller; - - return call_user_func(array($class, $func)); + + //echo "Found class"; + + call_user_func(array($class, $func)); + + return; } - // Function doesn't exist…404 + // Function doesn't exist...404 show_404(); + die(); } // If it gets here, it's still a 404 @@ -257,4 +303,4 @@ require_once('db.php'); //Route to the appropriate function route(); -// End of common.php \ No newline at end of file +// End of common.php diff --git a/sys/miniMVC.php b/sys/miniMVC.php index 0350041..edc305d 100644 --- a/sys/miniMVC.php +++ b/sys/miniMVC.php @@ -197,12 +197,14 @@ class MM_Controller extends miniMVC { $buffer = ob_get_contents(); ob_end_clean(); - if($return) + if($return == TRUE) { return $buffer; } - - $this->output->append_output($buffer); + else + { + $this->output->append_output($buffer); + } } } diff --git a/sys/output.php b/sys/output.php index 418af70..7ccb57b 100644 --- a/sys/output.php +++ b/sys/output.php @@ -39,6 +39,10 @@ class Output extends miniMVC { echo $this->buffer; ob_end_flush(); } + else + { + echo "No page content"; + } } /** diff --git a/sys/page.php b/sys/page.php index 1b382dc..b4a5674 100644 --- a/sys/page.php +++ b/sys/page.php @@ -434,12 +434,12 @@ class Page * @param string $message * @return void */ - public function set_message($type, $message) + public function set_message($type, $message, $return=FALSE) { $data['stat_class'] = $type; $data['message'] = $message; - $this->mm->load_view('message', $data); + return $this->mm->load_view('message', $data, $return); } // --------------------------------------------------------------------------