Location: PHPKode > projects > Phpgrid > core/common.php
<?php 

/**
 * common.php :: 公共执行的程序,任何访问URL都会经过此文件处理,以便于分发到相应的控制器上
 * 公共执行的程序
 * Power2php version 1.5
 *
 * @package core
 * @author diy,kate
 * @copyright Copyright (c) 2007-2008  by  diy,kate
 * @license GNU General Public License (GPL),
 * @website http://phpgrid.sf.net,
 */
// ------------------------------------------------------------------------

if ( ! defined('PROJECT_DIR')) exit('您必须在config.php中先定义常量PROJECT_DIR');

require_once(PROJECT_DIR."/config.php");
require_once(PROJECT_DIR."/core/controller.php") ;
require_once(PROJECT_DIR."/core/model.php") ;
require_once(PROJECT_DIR.'/libs/mypdo.class.php');
 

if(!empty($_POST)){
    
	$control=trim($_POST['control']);
	$action=trim($_POST['action']);
    if(file_exists(CONTROL_DIR."/".$control.".php")){
	  require_once(CONTROL_DIR."/".$control.".php");
 		  
	  $frame_obj=new $control();
      $frame_obj->$action();
		 

	  }else{
		  echo  "找不到文件:".CONTROL_DIR."/".$control.".php"."<br><font color=red>请检查表单提交上来的control隐藏域值是否正确,它的值应该为控制器的类名。</font><br>";
		  die;
	  
	  }

}

if(!empty($_GET)){
    @extract($_GET);
    if(file_exists(CONTROL_DIR."/".$control.".php")){
	      require_once(CONTROL_DIR."/".$control.".php"); 
		 
		 $frame_obj=new $control();
		 $frame_obj->$view();
		 // call_user_func(array($control, $view));

	  }else{
		  echo  "找不到文件:".CONTROL_DIR."/".$control.".php"."<br><font color=red>请检查URL传入的control参数是否正确,</font>如果正确在".CONTROL_DIR."下存在".$control.".php文件";
		  die;
	  
	  }

} else{
 redirect("index.php?control=index&view=view_index");


}



/**
 * 网页地址重定向函数
 *
 * @param string $URL 				要跳转的地址
 * @param string $redirectType		跳转的类型1用php的header()函数跳转,2用js的window.location.href函数,3用js的window.location.replace函数
 * 									
 */
function redirect( $URL, $redirectType = 3)
{
	switch($redirectType)
	{
		case 1:
			header("location: $URL");
			break;
		case 2:
			echo("<script language=\"JavaScript\" type=\"text/javascript\"> window.location.href = \"$URL\"; </script>");
			break;
		case 3:
			echo ' <SCRIPT>
       				 setTimeout("window.location.replace(\"'.$URL.'\")",500);
        		   </SCRIPT>';
			exit();
			break;
		default:
			trigger_error("unknown redirect type");
			break;
	}
	exit();
}

/**
 * 浏览器的后退操作函数
 *
 * @param string $alert_info  弹出对话框的信息
 */
function back($alert_info=""){
	
	if(empty($alert_info)){
		echo  "<script>window.history.back(-1); </script>";
		die;
	}else{
		echo  "<script>alert('$alert_info');window.history.back(-1); </script>";
		die;
	}  
}
 
/**
 * 浏览器的alert函数
 *
 * @param string $alert_info  弹出对话框的信息
 */
function alert($alert_info=""){
		echo  "<script>alert('$alert_info');</script>";
		die;
}
 
?>
Return current item: Phpgrid