标签 thinkPHP 下的文章

//基于layui修改弹框消息美化(TP5.0)
function alert($msg='',$url='',$icon='',$time=3){
    $str='<script type="text/javascript" src="'.config('admin_static').'/script/js/jquery.min.js"></script><script type="text/javascript" src="'.config('admin_static').'/script/lib/layui/layui.js"></script>';//加载jquery和layui
    $str.='<script>$(layui.use(\'layer\', function(){layer.msg("'.$msg.'",{icon:'.$icon.',time:'.($time*1000).'}, function(){location.href="'.$url.'"})}));</script>';//主要方法
    return $str;
}

//tp5.1(2019.5.27)
function alert($msg='',$url='',$icon='',$time=3){
    $str='<script type="text/javascript" src="/static/jquery.min.js"></script><script type="text/javascript" src="/static/admin/layui/layui.js"></script>';//加载jquery和layui
    $str.='<script>$(layui.use(\'layer\', function(){layer.msg("'.$msg.'",{icon:'.$icon.',time:'.($time*1000).'}, function(){location.href="'.$url.'"})}));</script>';//主要方法
    return $str;
}

1SQL运算符例子实际查询条件
eq=$map['id'] = array('eq',100);等效于:$map['id'] = 100;
neq!=$map['id'] = array('neq',100);id != 100
gt>$map['id'] = array('gt',100);id > 100
egt>=$map['id'] = array('egt',100);id >= 100
lt<$map['id'] = array('lt',100);id < 100
elt<=$map['id'] = array('elt',100);id <= 100
likelike$map['username'] = array('like','li%');username like 'li%'
betweenbetween and$map['id'] = array('between','1,8');id BETWEEN 1 AND 8
not betweennot between and$map['id'] = array('not between','1,8');id NOT BETWEEN 1 AND 8
inin$map['id'] = array('in','1,5,8');id in(1,5,8)
not innot in$map['id'] = array('not in','1,5,8');id not in(1,5,8)
and(默认)and$map['id'] = array(array('gt',1),array('lt',10));(id > 1) AND (id < 10)
oror$map['id'] = array(array('gt',3),array('lt',10), 'or');(id > 3) OR (id < 10)
xor(异或)xor两个输入中只有一个是true时,结果为true,否则为false,例子略。1 xor 1 = 0
exp综合表达式$map['id'] = array('exp','in(1,3,8)');$map['id'] = array('in','1,3,8');

注意:exp 不是一个运算符,而是一个综合表达式以支持更复杂的条件设置。exp 的操作条件不会被当成字符串,可以使用任何 SQL 支持的语法,包括使用函数和字段名称。

在JS中要使用php的数组需要先把数组转成json格式

如果传过来的php数组已经json_encode过了

var js_arr = eval(<?php echo $php_arr;?>);
//thinkPHP 可以这么写
var js_arr = eval('{$php_arr}');

如果传过来的数组没有json_encode过

var js_arr = eval(<?php echo json_encode($php_arr);?>);

查看js数组js_arr长度

console.log(js_arr.length);

遍历js_arr数组

for(var i = 0 ; i < js_arr.length ; i++){
    console.log(js_arr[i]);    
}

html+js

<textarea id="demo" style="display: none;"></textarea>
<script>
    layui.use('layedit', function(){
    var layedit = layui.layedit;
    uploadImage: {
        //上传操作 后台Article控制器的layeditUpload方法
        url: '{:U("Admin/Article/layeditUpload")}' //接口url
        ,type: '' //默认post
    }
    layedit.build('demo'); //建立编辑器
    });
</script>

php接收上传代码

public function layeditUpload(){
    $file = request()->file('file');
    // 移动到框架应用根目录/public/uploads/ 目录下
    $info = $file->move(ROOT_PATH . 'public' . DS . 'layeditUpload');
    $reubfo = array();  //定义一个返回的数组
    if($info){
        $reubfo['code']= 0;
        $reubfo['msg']= '上传成功';
        $reubfo['data']['src']= "/layeditUpload/".$info->getSaveName(); 
    }else{
        // 上传失败获取错误信息
        $reubfo['code']= -1;
        $reubfo['err'] = $file->getError();
    }
    return json($reubfo);
}

简单的给按钮加上确认弹框

下面是删除所有标签按钮例子(附TP5跳转地址):

<a href="javascript:if(confirm('确定删除所有标签?'))location='{:url('Tag/delall')}'">删除所有标签</a>

控制器代码

public function viewbug(){
    $where  = array();
    $name = '';
    if (Request::instance()->isPost()) {
        $name = $_POST['playerName'];
        $where['playerName'] = array('like',"%$name%");
    }
    $count = Db::name('ygo_bug')->where($where)->count();
    $bugs = Db::name('ygo_bug')->where($where)->order('id desc')->paginate(100);
    $this->assign('count',$count);
    $this->assign('name',$name);
    $this->assign('bugs',$bugs);
    return $this->fetch();
}

html代码

<div class="hui-pager hui-pager-center" style="padding:10px 30px;">{$bugs->render()}</div>

css代码

<style>
    .pagination { display: inline-block; padding-left: 0; margin: 20px 0; border-radius: 4px; }
    .pagination li { display: inline; }
    .pagination li a,.pagination li span { position: relative; float: left; padding: 6px 12px; margin-left: -1px; line-height: 1.428571429; text-decoration: none; background-color: #fff; border: 1px solid #ddd; }
    .pagination li:first-child a { margin-left: 0; border-bottom-left-radius: 4px; border-top-left-radius: 4px; }
    .pagination li:last-child a { border-top-right-radius: 4px; border-bottom-right-radius: 4px; }
    .pagination li a:hover, .pagination li a:focus { background-color: #eee; }
    .pagination .active span, .pagination .active span:hover, .pagination .active span:focus { z-index: 2; color: #fff; cursor: default; background-color: #428bca; border-color: #428bca; }
    .pagination .disabled span, .pagination .disabled span:hover, .pagination .disabled span:focus { color: #999; cursor: not-allowed; background-color: #fff; border-color: #ddd; }
    .pagination-lg li a { padding: 10px 16px; font-size: 18px; }
    .pagination-sm li a, .pagination-sm li span { padding: 5px 10px; font-size: 12px; }
</style>

server {
    listen  80;
    server_name  home.zhouqq.com;
    root /www/zhouqq;
    index  index.html index.htm index.php;
    error_page  404              /404.html;
    location = /404.html {
        return 404 'Sorry, File not Found!';
    }
    error_page  500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html; # windows用户替换这个目录
    }
    location / {
        try_files $uri @rewrite;
    }
    location @rewrite {
        set $static 0;
        if  ($uri ~ \.(css|js|jpg|jpeg|png|gif|ico|woff|eot|svg|css\.map|min\.map)$) {
            set $static 1;
        }
        if ($static = 0) {
            rewrite ^/(.*)$ /index.php?s=/$1;
        }
    }
    location ~ /Uploads/.*\.php$ {
        deny all;
    }
    location ~ \.php/ {
       if ($request_uri ~ ^(.+\.php)(/.+?)($|\?)) { }
       fastcgi_pass 127.0.0.1:9000;
       include fastcgi_params;
       fastcgi_param SCRIPT_NAME     $1;
       fastcgi_param PATH_INFO       $2;
       fastcgi_param SCRIPT_FILENAME $document_root$1;
    }
    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
    location ~ /\.ht {
        deny  all;
    }
}