码迷,mamicode.com
首页 > Web开发 > 详细

thinkphp笔记

时间:2017-06-06 11:56:41      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:var   自定义   session   text   admin   err   add   stat   error   

1,thinkphp框架修改值方法
$info = D(‘biao‘)->where(‘lie = ‘.$bianliang)->setfield(‘lie‘,$bianliang);

2,db操作log

ThinkPHP/Library/Think/Db.class.php 中update和delete等(除了insert)中加入

 $userlog = M("useroplog");

$log = ‘‘;

$userlog->add($ar);

3,tp3.2自定义成功出错方法

    public function success1($info,$url=‘‘){
           $data[‘info‘]=$info;
           $data[‘status‘]=1;
           $data[‘url‘]=$url;
           echo  json_encode($data);
           die;
    }
    public function error1($info,$url=‘‘){
            $data[‘info‘]=$info;
            $data[‘status‘]=0;
            $data[‘url‘]=$url;
            echo  json_encode($data);
        die;
    }

  

4,Contrlller.class.php构造方法中加入验证

        //验证
        $now_c = CONTROLLER_NAME;
        $now_a = ACTION_NAME;
        if(empty($_SESSION[usession])  ) {
            if($now_c!=Signin ){
              if( $now_c != Index && $now_a != index) {
                die("error!");
              }
            }
        }

 

5,异步提交代码

<script type="text/javascript" src="/public/js/layer/layer.js"></script>
//head中引入layer.js

{literal}//smarty模板原样输出要加上这个
<script>
    $(‘#submit‘).click(function(){
        var name = $("#admin_user").val();
        var pwd = $("#admin_psd").val();
        if(name.length>2){
            if(pwd.length>0){
                $.post("/index.php/Admin/login",$("#reg-form").serialize(),function(res){
                    if(res.status==0){
                        layer.msg(res.info,{icon:2})
                    }else{
                        layer.msg(‘登录成功‘,{icon:1},function(){
                        location.href="/index.php/Admin/index";
                        })
                    }
                },‘json‘)

            }else{
                layer.msg(‘密码不能为空‘,{icon:2})
            }

        }else{
            layer.msg(‘账号格式不正确至少三个字符‘,{icon:2});
        }
    })
</script>
{/literal}

 

thinkphp笔记

标签:var   自定义   session   text   admin   err   add   stat   error   

原文地址:http://www.cnblogs.com/Crius/p/thinkphp.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!