1个回答
展开全部
<?php
//这是以前写的代码 你这里稍微修改一下就OK了
class AppAction extends ApiAction
{
//域名对应模块
public $open_domain_support = true;
public function __construct(){
parent::__construct();
}
/**
* 处理子模块,调用子模块下面的action
*/
public function _empty(){
$module_info = $this->get_module_info();
$action_name = $module_info['action'];
$action_name = ucfirst(parse_name($action_name,1));
$file =APPLICATION_PATH.'Api/Action/App/'.$action_name.'Action.class.php';
if(file_exists($file)){
$method = $module_info['method'];
$vars = $module_info['vars'];
$count = count($vars);
for($i = 0;$i < $count;$i = $i+2){
$next_index = $i+1;
$_GET[$vars[$i]] = isset($vars[$next_index]) ? $vars[$next_index] : '';
}
require $file;
$action_name = $action_name.'Action';
$action = new $action_name;
//$action->$method;
call_user_func(array($action,$method));
}
}
/**
* 获取模块信息
*/
public function get_module_info(){
$index_start = $this->open_domain_support ? 2 : 3;
if(isset($_SERVER['REDIRECT_URL']) && $_SERVER['REDIRECT_URL']){
$_SERVER['REDIRECT_URL'] = str_replace('.html', '', $_SERVER['REDIRECT_URL']);
$url_arr = explode('/',$_SERVER['REDIRECT_URL']);
$action = isset($url_arr[$index_start])? $url_arr[$index_start] : 'Index';
$method = isset($url_arr[$index_start+1])?$url_arr[$index_start+1]:'index';
$method = $method ? $method : 'index';
$vars = array_slice($url_arr,$index_start+2);
}else{
$_SERVER['PHP_SELF'] = str_replace('.html', '/', $_SERVER['PHP_SELF'].$_SERVER['REQUEST_URI']);
$url_arr = explode('/',$_SERVER['PHP_SELF']);
$action = $url_arr[$index_start+1];
$method = isset($url_arr[$index_start+2])?$url_arr[$index_start+2]:'index';
$method = $method ? $method : 'index';
$vars = array_slice($url_arr,$index_start+3);
if(count(explode('?',$method)) >= 2){
$tmp=explode('?',$method);
// dump($action);
// exit;
if($url_arr[2] == 'User'){
$method = 'index';
}else{
$method = $tmp[0];
}
$vars = array_slice($url_arr,$index_start+2);
}else{
$vars = array_slice($url_arr,$index_start+3);
}
}
return array('action'=>$action,'method'=>$method,'vars'=>$vars);
}
public function appReturn($data,$msg='成功返回',$state=1){
$var=[
'data'=>$data,
'msg'=>$msg,
'state'=>$state,
];
$this->ajaxReturn($var);
}
}
//这是以前写的代码 你这里稍微修改一下就OK了
class AppAction extends ApiAction
{
//域名对应模块
public $open_domain_support = true;
public function __construct(){
parent::__construct();
}
/**
* 处理子模块,调用子模块下面的action
*/
public function _empty(){
$module_info = $this->get_module_info();
$action_name = $module_info['action'];
$action_name = ucfirst(parse_name($action_name,1));
$file =APPLICATION_PATH.'Api/Action/App/'.$action_name.'Action.class.php';
if(file_exists($file)){
$method = $module_info['method'];
$vars = $module_info['vars'];
$count = count($vars);
for($i = 0;$i < $count;$i = $i+2){
$next_index = $i+1;
$_GET[$vars[$i]] = isset($vars[$next_index]) ? $vars[$next_index] : '';
}
require $file;
$action_name = $action_name.'Action';
$action = new $action_name;
//$action->$method;
call_user_func(array($action,$method));
}
}
/**
* 获取模块信息
*/
public function get_module_info(){
$index_start = $this->open_domain_support ? 2 : 3;
if(isset($_SERVER['REDIRECT_URL']) && $_SERVER['REDIRECT_URL']){
$_SERVER['REDIRECT_URL'] = str_replace('.html', '', $_SERVER['REDIRECT_URL']);
$url_arr = explode('/',$_SERVER['REDIRECT_URL']);
$action = isset($url_arr[$index_start])? $url_arr[$index_start] : 'Index';
$method = isset($url_arr[$index_start+1])?$url_arr[$index_start+1]:'index';
$method = $method ? $method : 'index';
$vars = array_slice($url_arr,$index_start+2);
}else{
$_SERVER['PHP_SELF'] = str_replace('.html', '/', $_SERVER['PHP_SELF'].$_SERVER['REQUEST_URI']);
$url_arr = explode('/',$_SERVER['PHP_SELF']);
$action = $url_arr[$index_start+1];
$method = isset($url_arr[$index_start+2])?$url_arr[$index_start+2]:'index';
$method = $method ? $method : 'index';
$vars = array_slice($url_arr,$index_start+3);
if(count(explode('?',$method)) >= 2){
$tmp=explode('?',$method);
// dump($action);
// exit;
if($url_arr[2] == 'User'){
$method = 'index';
}else{
$method = $tmp[0];
}
$vars = array_slice($url_arr,$index_start+2);
}else{
$vars = array_slice($url_arr,$index_start+3);
}
}
return array('action'=>$action,'method'=>$method,'vars'=>$vars);
}
public function appReturn($data,$msg='成功返回',$state=1){
$var=[
'data'=>$data,
'msg'=>$msg,
'state'=>$state,
];
$this->ajaxReturn($var);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询