代码改变世界

PHP路由功能的实现之genesis分析记录

2015-11-21 11:33  潇洒肥猫  阅读(222)  评论(0)    收藏  举报

一、客户端

由JavaScript实现,或者由cocos2d js客户端实现,http请求

通用参数:_fk_s、_fk_pf、access_token、open_id、pfkey、cwptime

不同功能定制化参数: 例如

act:“workon”

proid:78

ps:0

times:1

二 、服务器端

1. 总控入口程序 :ajax/civwar.php

$ajax = new CivWarAjax($_GET);
$ajax->prepare();

 构造函数代码如下

function __construct($request) {
        //新建Application对象
        global $gSmarty,$G_LANG,$is_production,$memcache;
        if($is_production==2) {
            $this->app = new CivWarApplication(56, "", "","","");
        } else {
            $this->app = FaceKoo::getElementObject($this->appId);
        }
        //检查登陆情况
         check_login_forajax();
        //新建Character对象
         $this->character = $this->app->getCharacter($this->userId,false,false,false,$act);
       }

 prepare()函数代码:

            $methodName = $act."InfoDetail";//动态拼接方法名称
            if(method_exists($this,$methodName)) {
                $rtn = $this->$methodName($page);
            } else {
                $rtn = "{rtn_code:'0'}";
            }
所有的逻辑处理函数都是以act+InfoDetail命名,这里动态