thinkphp笔记

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}

 

posted on 2017-06-06 11:20  coding-farmer  阅读(159)  评论(0编辑  收藏  举报

导航