1.继承单一控制器
我们在写thinkphp控制器的时候,都是单独的控制器文件,在实际的项目中每个控制器可能都需要相关同样的验证,这种情况我们就可以的使用公共的控制器里写入对应的验证,其他控制器直接继承就好了这里面thinkphp.12为例子
/**
*公共控制器
*/
classCommonAction extendsAction {
publicstatic$global;
publicstatic$model;
publicfunction__construct(){
self::$global=getGolVal();
//dump(self::$global);
$navList=getNavlist(0,6);
$this->assign('list',$navList);
$this->assign('g',self::$global);
}
publicfunctionerror(){
$this->display('404');
}
/**
*
* Enter description here ...
*/
publicstaticfunctionnavLists($id,$type=0){
$id=intval($id);
self::$model=M('Category');
if($type==0){
$leftList=self::$model->where("parent_id=0 and mark=1 and type=0 ")->select();
}elseif($type==1){
$leftList=self::$model->where("id={$id} and mark=1 ")->find();
if($leftList['parent_id']==0){//顶级栏目
$leftList=self::$model->where("parent_id={$id} and mark=1 ")->select();
if(!is_array($leftList)){//顶级栏目 没有的子栏目话就显示
$leftList=self::$model->where("id={$id} and mark=1 ")->find();
$tempList=array();
$tempList[]=$leftList;
$leftList=$tempList;
}
}else{
$tempList=array();
$tempList[]=$leftList;
$leftList=$tempList;
}
}
/*dump($leftList);
dump(self::$model->getLastSql());*/
return$leftList;
}
}
额外的小知识,虽然在thinkphp中M()函数实例化模型,返回是一个静态变量,但是M方法却不是静态调用的,所以我们在多次调用M()时候尽量多使用静态属性,以提高好的效率。action操作里面尽量使用局部函数,减少资源消耗。
/**
*other控制器
*/
classOtherAction extendsCommonAction {
//code
}
2.对于post,get传来的值可以使用$this->_post();$this->_get();
$this->_post();$this->_get();
这个函数默认就会使用htmlspecialchars()进行过滤,不用手动过滤。哈哈,省了不少功夫吧
在thinkphp3.1.3中有一个新的函数I();直接接收表单数据,并默认为htmlspecailchars();过滤这个函数有这些字段 I('需要接收的表单名','如果数据为空默认值','使用的函数处理表单数据');
U();函数是输出地址
U('操作名','array()参数','伪静态后缀名',是否跳转,域名)
荒野乱斗国际版 (BrawlStars)最新版本v56.274
下载一波超人内置修改器菜单版 安卓版v1.0.2
下载敢达决战官方正版 安卓版v6.7.9
下载敢达决战 安卓版v6.7.9
下载继承了一座戏园子无限声望铜钱版 内置菜单最新版v1.7
继承了一座戏园子折相思版是游戏的破解版本,在该版本中为玩家提
山河半世橙光清软金手指版 无限鲜花v3.24
山河半世是一款超级好玩的橙光恋爱游戏,在游戏中玩家们需要扮演
蓬莱手游折相思版 安卓版v1.0.0
蓬莱免广告版是游戏的修改版本,在该版本中为玩家去除了广告,玩
当红影后橙光游戏破解版2025 最新版v1.0
当红影后橙光破解版是一款超级好玩的娱乐圈题材的橙光游戏,在这
忽然成了万人迷清软完结版 无限鲜花版v12.15
忽然成了万人迷破解版是一款非常好玩的男性向橙光游戏,在有一天