thinkphp5分页获取的对象数据怎么遍历修改?

浏览:3317 发布日期:2017/10/31 分类:求助交流 关键字: 对象 分页 转换
把用分页查询出来的对象数据中的所有url转换为对应友好的文字描述。<?php
namespace app\common\model;
use think\Model;
use think\Db;
/**
* 后台操作日志
*/
class OperationLog extends Model
{
    protected $pk = 'id';
    protected $table = 'app_access_log';
    protected $insert = ['created_time'];

    protected function setCreatedTimeAttr($value){
        return date("Y-m-d H:i:s");
    }

    public function operationList(){
        $result = Db::table('app_access_log')->alias('a')->join('__USER__ u','a.uid=u.id','LEFT')
            ->field( 'a.target_url,a.query_params,a.ip,a.created_time,u.username' )
            ->paginate(50);

        $replace =[
            'page1',
            'page2',
            'page3',
            'page4',
            '用户查看',
            '用户添加',
            '用户操作日志列表'
        ];
        $search  = [
            '/index.php/rbac/index/page1.html',
            '/index.php/rbac/index/page2.html',
            '/index.php/rbac/index/page3.html',
            '/index.php/rbac/index/page4.html',
            '/index.php/rbac/user/index.html',
            '/index.php/rbac/user/useradd.html',
            '/index.php/rbac/operation_log/index.html',
        ];

        foreach ($result as $key => &$value) {
            // dump($value['target_url']);
            $value['target_url'] = str_replace($search, $replace, $value['target_url']);
        }
        return $result;
    }
}
最佳答案
评论() 相关
后面还有条评论,点击查看>>