PHP code example of cocolait / think

1. Go to this page and download the library: Download cocolait/think library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cocolait / think example snippets


composer 


//在控制器用使用
$page = $request->param('page',1,'int');//获取分页上的page参数
$request = Request::instance();//获取请求体对象
$start = 0;
$limit = 10;//默认显示多少条
$where = ['uid' => ['>',1]];
if ($page != 1) {
    $start = ($page-1) * $limit;
}
// 根据筛选条件查询数据
$data = Db::table('user')->where($where)->limit($start,$limit)->select();

// 查询总记录数
$total = Db::table('user')->where($where)->count();

$pageNum = 0;
// 计算总页数
if ($total > 0) {
    $pageNum = ceil($total/$limit);
}

// 分页输出显示 不管有没有查询条件写法都是一致的 只需要把请求体放到第三个参数就行
$pageShow = \cocolait\extend\page\Send::instance(['total'=>$total,'limit' => $limit])->render($page,$pageNum,$request->param());



// token有心跳机制 当用户登录成功后在token有效期之类会根据心跳值来叠加token的生命周期
// 获取用户登录后的token 分配给前端
$data = \cocolait\extend\auth\Token::instance()->getAccessToken($uid);
// 验证token
$token = 'apMuQuY3SgKqNzYm4s6qGzJNsgY57nYehhKKJrMjQhHeCzY-2l85_l';
$data = \cocolait\extend\auth\Token::instance()->checkAccessToken($token);