时间戳转换工具

类似$db->where("id=36")->limit("10")->order("uid desc"),链式操作的实现方式


先讲下方法的常规调用;

namespace Com;

class Database{

    function where($where){
        echo $where;
    }

    function order($order){
        echo $order;
    }

    function limit($limit){
        echo $limit;
    }
}

调用
$db = new  \Com\Database();
$db->where();
$db->limit();
缺点:实现多个方法需要多行调用;

链式操作,在方法返回return $this;即可使用链式操作;
namespace Com;

class Database{

    function where($where){
        echo $where;


        return $this;
    }

    function order($order){
        echo $order;


        return $this;
    }

    function limit($limit){
        echo $limit;


        return $this;
    }
}

使用链式调用:
$db->where("id=36")->limit("10")->order("uid desc")  ;

联系我们 - 首页 - 关于我们
Copyright © 2017-2022 iteam. All Rights Reserved. Current version is 2.50.0.
粤ICP备17021424号
VV:46383 UV:165336 PV:515933