这里只是分享一些实际开发过程所需的一些功能方法
1.分页的实现paginate方法
$dateParam['query']['startDate'] = $startDate;
$dateParam['query']['countryCode'] = $countryCode;
$dateParam['query']['endDate'] = $endDate;
$feedbackList = db()->table('store_feedback')->where($where)->order('email desc,create_time desc')->paginate(10,false,$dateParam);
$page = $feedbackList->render();
返回feedbackList
$dateParam是承载查询参数的对象
web上应该写成这个瘠薄样子,注意参数写法不要写错
这里是表单渲染,这个写法据说是tp5的语法,但是跟java的没多大卵区别
{if condition='$type == 1'}
Game Name
Content
Num
Time
{volist name="$gmbFeedbackList" id="v"}
{$v.game_name}
{if condition='$v.content == 1'}
Unable to down
{elseif condition='$v.content == 2'/}
Updates needed
{elseif condition='$v.content == 3'/}
Crash
{elseif condition='$v.content == 4'/}
Unable to install
{else/}
error
{/if}
{$v.num}
{$v.time}
{/volist}
{$page}
{else/}
Game Name
content
Email
Image
Time
{volist name="$gmbFeedbackList" id="v"}
{$v.game_name}
{$v.content}
{$v.email}
{$v.create_time}
{/volist}
{$page}
{/if}
2.mysql行转列 恩是的就是oracle的decode
SELECT
t2.game_name,
MAX( CASE t2.content WHEN '1' THEN t2.num ELSE 0 END ) AS 'content1',
MAX( CASE t2.content WHEN '2' THEN t2.num ELSE 0 END ) AS 'content2',
MAX( CASE t2.content WHEN '3' THEN t2.num ELSE 0 END ) AS 'content3',
MAX( CASE t2.content WHEN '4' THEN t2.num ELSE 0 END ) AS 'content4',
t2.time date
FROM
(
SELECT
game_name,
content,
count( 1 ) num,
date( gf.create_time ) time
FROM
gmb_feedback gf
LEFT JOIN gmb_game gg ON gf.game_id = gg.id
WHERE
gf.content IN ( '1', '2', '3', '4' )
AND date( gf.create_time ) = '2018-08-15'
GROUP BY
gg.game_name,
gf.content
) t2
GROUP BY
t2.game_name
3.获取远程文件大小的方法,单位是kb,为什么是kb?别问,问就巴掌
function getFileSize($url){
$file = get_headers($url);
$fileSizeStr = $file[2];
$fileSize = substr($fileSizeStr,16);
$fileSize = round($fileSize/1024);
return $fileSize;
}
4.比较版本号的方法,tp5自带的一个version_compare,就是要重写一个,不接受反驳(╰_╯)#
function versionCompare($versionA, $versionB)
{
if ($versionA > 2147483646 || $versionB > 2147483646) {
throw new Exception('版本号,位数太大暂不支持!', '101');
}
$dm = '.';
$verListA = explode($dm, (string)$versionA);
$verListB = explode($dm, (string)$versionB);
$len = max(count($verListA), count($verListB));
$i = -1;
while ($i++ < $len) {
$verListA[$i] = intval(@$verListA[$i]);
if ($verListA[$i] < 0) {
$verListA[$i] = 0;
}
$verListB[$i] = intval(@$verListB[$i]);
if ($verListB[$i] < 0) {
$verListB[$i] = 0;
}
if ($verListA[$i] > $verListB[$i]) {
return 1;
} else if ($verListA[$i] < $verListB[$i]) {
return -1;
} else if ($i == ($len - 1)) {
return 0;
}
}
}
5.paginate点击下一页保留参数的方法
$dateParam['query']['endDate'] = $endDate
$feedbackList = db()->table('store_feedback')->where($where)->order('email desc,create_time desc')->paginate(10,false,$dateParam);
$page = $feedbackList->render();
在前端
2.分页包含each方法可以对结果集进行二次处理
3.简易的点击图片放大缩小
这里采用每条记录的主键+二维数组的第二维度便利产生的下标定义为id的值,这只适应二维数组的第二维度list里对象数量不超过两位数,否则出现id重复
当出现二维度list对象数量超过10的情况 id可在此基础上加上字段名
js如下
function changeSize(id,pictureUrl){
var img_url = pictureUrl;
var image = new Image();
image.src = img_url;
var tw = image.width;
var th = image.height;
var img = $("#"+id);
var oWidth=img.width(); //取得图片的实际宽度
var oHeight=img.height(); //取得图片的实际高度
$("#"+id).live("click",function(){
$(this).toggle(function(){
img.width(tw);
img.height(th);
}, function(){
img.width(oWidth);
img.height(oHeight);
}).trigger('click');
});
}
小Tips:
select语句可用db()->query();
update,delete语句用db()->excute()