zoukankan      html  css  js  c++  java
  • [轉]让PHP支持像jQuery那样的链式操作

    From : http://x1989.com/a/94.html

    群里有人讨论这个问题,我的想法是在方法里返回this指针(指向对象本身),通过对私有成员$sql的赋值,来获得最终的执行语句,并返回相应结果。

    Class Database{
    private $sql;
    public function where($condition){
    //此处省略n行...
    return this;
    }
    public function limit($limit){
    //此处省略n行...
    return this;
    }
    public function execute(){
    return this->query($sql);
    }
    public function select(){
    //此处省略n行...
    return this;
    }
    }
    //调用时:
    $DB = new Database();
    $DB->where($condition)->limit(20)->select();
  • 相关阅读:
    基于Flask开发web微信
    爬取实例
    scrapy框架学习之路
    scripy
    wtforms
    由testcase数据之分析
    无用之flask学习
    无用之flask
    无用之学matplotlib,numpy,pandas
    jsp_1
  • 原文地址:https://www.cnblogs.com/Athrun/p/2242202.html
Copyright © 2011-2022 走看看