findAll()分页的建议

#1 tanidea

findAll()空数据时,返回的是空数组,但使用findAll()分页,空数据时,返回的却是false。
我感觉findAll()分页空数据时,也应该返回空数组。
这样findAll()返回数据格式统一,findAll()返回的数据可以直接放到foreach里。

我自己是已经改了的

2017-12-30 13:21:35

#2 jake

新版的findAll(),从代码上来说,返回都是一样的。
没看出来分页后有不一样 https://github.com/SpeedPHP/spee ... /lib/speed.phpL223

分页的逻辑只是改变了findAll的limit值,这对结果的形态没有影响哦。



2017-12-30 21:02:53

#3 tanidea

我的代码格式:
$rst = $mod->findAll();
foreach($rst as $k=>$v){
    // code
}
findAll()不加入分页时,foreach没有出错,加入分页后,如果没有返回数据,foreach出错。
https://github.com/SpeedPHP/speed/blob/master/protected/lib/speed.phpL223
215行,是不是返回false?

我就遇到这情况

2017-12-30 21:54:03

#4 jake

这里追查一下,findAll调用query调用execute,最后返回结果是:
https://github.com/SpeedPHP/spee ... /lib/speed.phpL328
也就是PDO的$sth->fetchAll(PDO::FETCH_ASSOC) 返回,

看手册http://cn.php.net/manual/zh/pdostatement.fetchall.php

官方手册对返回值的描述是:PDOStatement::fetchAll() 返回一个包含结果集中所有剩余行的数组。此数组的每一行要么是一个列值的数组,要么是属性对应每个列名的一个对象。

这里官方手册没有说到,如果分页或者不分页,也就是SQL语句中的LIMIT有不同的值,就会有不同的返回值。
你可以试试看看错误提示,dumpSql等方式进行调试看看。


2017-12-30 22:08:03

#5 tanidea

你还没有明白哦。
没到query,更没到execute,findAll()直接返回了false。
https://github.com/SpeedPHP/speed/blob/master/protected/lib/speed.phpL223
215行,直接返回了false。

2017-12-30 22:45:38

#6 tanidea

tanidea 发表于 2017-12-30 22:45
你还没有明白哦。
没到query,更没到execute,findAll()直接返回了false。
https://github.com/SpeedPHP/sp ...
https://github.com/SpeedPHP/speed/blob/master/protected/lib/speed.phpL215

2017-12-30 22:58:43

#7 jake

tanidea 发表于 2017-12-30 22:45
你还没有明白哦。
没到query,更没到execute,findAll()直接返回了false。
https://github.com/SpeedPHP/sp ...
mark,没留意这行了,我的错,呵呵。

稍候修改过来。

2017-12-31 17:21:47

#8 jake

已修正,感谢
https://github.com/SpeedPHP/speed/commit/d5bf8c69bab87ef8aa01dd6b806201f58b7396da

2018-01-02 08:51:05

#9 tanidea

不客气。

另外有一个问题要请教你jake。

WEB编辑器,查看源代码时,是怎么做到代码自动缩进的呢?

就是xhEditor这种编辑器

2018-01-05 19:44:20

#10 jake

tanidea 发表于 2018-1-5 19:44
不客气。

另外有一个问题要请教你jake。
xheditor好像没这功能,不过在cms上面用的CodeMirror是有这个功能的。


现在我用得比较多的是markdown,markdown的代码缩进就简单了

2018-01-05 21:15:01