首页 > 代码库 > thinkphp笔记

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="http://www.mamicode.com/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="http://www.mamicode.com/index.php/Admin/index";
                        })
                    }
                },‘json‘)

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

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

 

thinkphp笔记