Miscellaneous Fixes

This commit is contained in:
Timothy Warren 2011-12-30 16:41:25 -05:00
parent 17b8bdbc6b
commit a72f8d332f
6 changed files with 70 additions and 17 deletions

View File

@ -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');

View File

@ -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()

View File

@ -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
*/
@ -142,7 +181,7 @@ function route()
$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

View File

@ -197,12 +197,14 @@ class MM_Controller extends miniMVC {
$buffer = ob_get_contents();
ob_end_clean();
if($return)
if($return == TRUE)
{
return $buffer;
}
else
{
$this->output->append_output($buffer);
}
}
}

View File

@ -39,6 +39,10 @@ class Output extends miniMVC {
echo $this->buffer;
ob_end_flush();
}
else
{
echo "No page content";
}
}
/**

View File

@ -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);
}
// --------------------------------------------------------------------------