grape动态PHP结构(三)
标签:
一、app视图与控制器1)路由
这里的v1、v2就是模块,由于客户端版本一直在迭代的,那么一些老版本的客户端调用的接口就得保留起来,使得兼容。新版本就直接调用新接口。
还有一种是写html页面,在客户端展示,只要把template文件夹和data文件夹加上就可以了。
Controller的配置如下,注意ismodule是true,module_list中的array:
$InitPHP_conf[‘ismodule‘] = true; //开启module方式 $InitPHP_conf[‘controller‘][‘path‘] = ‘controller‘; $InitPHP_conf[‘controller‘][‘controller_postfix‘] = ‘Controller‘; //控制器文件后缀名 $InitPHP_conf[‘controller‘][‘action_postfix‘] = ‘‘; //Action函数名称后缀 $InitPHP_conf[‘controller‘][‘default_controller‘] = ‘index‘; //默认执行的控制器名称 $InitPHP_conf[‘controller‘][‘default_action‘] = ‘index‘; //默认执行的Action函数 $InitPHP_conf[‘controller‘][‘module_list‘] = array(‘v1‘,‘v2‘); //module白名单 $InitPHP_conf[‘controller‘][‘default_module‘] = ‘v1‘; //默认执行module $InitPHP_conf[‘controller‘][‘default_before_action‘] = ‘before‘; //默认前置的ACTION名称 $InitPHP_conf[‘controller‘][‘default_after_action‘] = ‘after‘; //默认后置ACTION名称
这里顺便说下InitPHP的路由管理。InitPHP的框架URL路由分为三种形式,原生、path模式、rewrite模式,HTML模式。我这边用的是rewrite模式。
1.原生模式:index.php?c=index&a=run
2.rewrite模式:/index/run/id=1 (需要开启服务器rewrite模块,并且配置.htaccess)
3.path模式:/index/run/id/1 (需要开启服务器rewrite模块,并且配置.htaccess)
4.html模式: user-index-run.htm?uid=100 (需要开启服务器rewrite模块,并且配置.htaccess)
2)模拟session
这里模拟的方法比较简单而粗暴。
在登录的时候,会生成一串字符,然后保存到用户表中,这串字符会返回给客户端,作为session。
温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/67334.html