<NME> loader.php
<BEF> <?php
define('APP_TIME_START', microtime(true));
define('IPHP_PATH', dirname(__FILE__));
include_once(dirname(__FILE__) . '/functions.php');

mb_internal_encoding("UTF-8");

$AUTOLOAD_PATH =  array(
	dirname(__FILE__) . '/framework',
	APP_PATH . '/models',
	APP_PATH . '/classes',
);

spl_autoload_register(function ($cls){
	global $AUTOLOAD_PATH;
	foreach($AUTOLOAD_PATH as $dir){
		$file = $dir . '/' . $cls . '.php';
		if(file_exists($file)){
			require_once($file);
			return;
		}
	}
	// 有很多代码会使用 class_exists(), 需要和它们兼容, 所以不能在这里 throw
#	if(!class_exists($cls, false)){
#		throw new Exception("Class $cls not found!");
#	}
});

// init application
App::init();

	return false;
}

function find_view_file($base, $action){
	foreach(App::$controller->view_path as $view_path){
		$dir = rtrim(APP_PATH . "/$view_path/$base", '/');
		if($action == 'index'){
			$file = $dir . '.tpl.php';
		}else{
			$file = $dir . "/$action.tpl.php";
		}
		if(file_exists($file)){
			return $file;
		}
	}
	return false;

<MSG> refactor _view()

<DFF> @@ -126,16 +126,25 @@ function find_layout_file(){
 	return false;
 }
 
-function find_view_file($base, $action){
-	foreach(App::$controller->view_path as $view_path){
-		$dir = rtrim(APP_PATH . "/$view_path/$base", '/');
-		if($action == 'index'){
-			$file = $dir . '.tpl.php';
+function find_view_file(){
+	foreach(include_paths() as $path){
+		// 由 Controller 指定模板的名字
+		if(App::$controller->action && App::$controller->action != 'index'){
+			$action = App::$controller->action;
 		}else{
-			$file = $dir . "/$action.tpl.php";
+			$action = $path['action'];
 		}
-		if(file_exists($file)){
-			return $file;
+		$base = $path['base'];
+		foreach(App::$controller->view_path as $view_path){
+			$dir = rtrim(APP_PATH . "/$view_path/$base", '/');
+			if($action == 'index'){
+				$file = $dir . '.tpl.php';
+			}else{
+				$file = $dir . "/$action.tpl.php";
+			}
+			if(file_exists($file)){
+				return $file;
+			}
 		}
 	}
 	return false;

refactor _view()