所谓链式操作最简单的理解就是 操作完毕之后再返回对象$this 想必大家工作中基本都快用烂了得东西。

下面就是一个链式操作MYSQL数据库类。

最常见的链式操作 每一个方法操作之后,返回一个对象,直到最后一个方法才是执行和返回整个链式操作的结果。

$model->where()->field()->limit()->select()
<?php
namespace FrameWork; class DataBase
{ public function __construct()
{ } public function where()
{
return $this;
} public function orderBy()
{
return $this;
} public function limit()
{
return $this;
} public function select()
{
return $this;
}
} $obj = new DataBase(); //链式操作
$obj->where()->limit()->orderBy()->select();

PHP 链式操作的更多相关文章

  1. 用php实现一个简单的链式操作

    最近在读<php核心技术与最佳实践>这本书,书中第一章提到用__call()方法可以实现一个简单的字符串链式操作,比如,下面这个过滤字符串然后再求长度的操作,一般要这么写: strlen( ...

  2. PHP中的__toString方法(实现JS里的链式操作)

    _toString方法是在打印对象时自动调用的魔术方法,如果不声明会报以下错 Catchable fatal error: Object of class String could not be co ...

  3. jQuery链式操作[转]

    用过jQuery的朋友都知道他强大的链式操作,方便,简洁,易于理解,如下 $("has_children").click(function(){ $(this).addClass( ...

  4. PHP链式操作输出excel(csv)

    工作中经常会遇到产品运营让导出一些简单的比较规范的数据,这时候要是有一个简单的方法可以用就简单多了.下面是我的一个输出简单的excel(csv)的方法类,用到了链式操作.说到链式操作,在jquery中 ...

  5. php类自动装载、链式操作、魔术方法

    1.自动装载实例 目录下有3个文件:index.php load.php tests文件夹 tests文件夹里有 test1.php <?php namespace Tests; class T ...

  6. PHP 设计模式 笔记与总结(4)PHP 链式操作的实现

    PHP 链式操作的实现 $db->where()->limit()->order(); 在 Common 下创建 Database.php. 链式操作最核心的地方在于:在方法的最后 ...

  7. 如何一行jquery代码写出tab标签页(链式操作)

    啦啦!今天又学了一招,js写几十行的tab标签页jquery写一行就行啦,用到了链式操作!以下是代码: <!DOCTYPE html> <html lang="en&quo ...

  8. jquery中链式操作的this指向

    jquery中链式操作是如何实现? 例如:$(obj).children().css('color','red').next().css('color','red').siblings().css(' ...

  9. php 链式操作的实现 学习记录

    php 面向对象中实现链式操作的关键部分:调用的方法中返回当前对象 ,从而实现链式操作: <?php namespace commom; class db { public function w ...

随机推荐

  1. easyui tab 关闭

    <div id="mm" class="easyui-menu" style="width:150px;">        &l ...

  2. python-day7 python内置模块 面向对象

    1.configparser模块 configparser用于处理特定格式的文件,其本质上是利用open来操作文件 # 注释1 ; 注释2 [section1] # 节点 k1 = v1 # 值 k2 ...

  3. CSU 1325: A very hard problem 中南月赛的一道题。

    1325: A very hard problem Time Limit: 3 Sec  Memory Limit: 160 MBSubmit: 203  Solved: 53[Submit][Sta ...

  4. 2016年12月3日 星期六 --出埃及记 Exodus 20:24

    2016年12月3日 星期六 --出埃及记 Exodus 20:24 "`Make an altar of earth for me and sacrifice on it your bur ...

  5. 2016年11月5日 星期六 --出埃及记 Exodus 19:21

    2016年11月5日 星期六 --出埃及记 Exodus 19:21 and the LORD said to him, "Go down and warn the people so th ...

  6. 2016年10月13日 星期四 --出埃及记 Exodus 18:24

    2016年10月13日 星期四 --出埃及记 Exodus 18:24 Moses listened to his father-in-law and did everything he said.于 ...

  7. webkit和xcode

    一.webkit下载地址:https://svn.webkit.org/repository/webkit/ 它的总大小为2.75G 二.xcode下载地址:http://adcdownload.ap ...

  8. ios事件传递

    http://blog.csdn.net/iefreer/article/details/4754482 本章描述了iPhone操作系统里的事件类型,并解释了如何处理它们.还讨论了怎么在一个应用程序里 ...

  9. vim基本使用

    i 进入插入状态 esc 退出插入状态 x 删除一个字符 dd 删除一行,并拷贝 yy 拷贝 p 粘贴 u 撤销 ctrl+r 重做 :w 保存 :q 退出 :q! → 退出不保存

  10. 《JAVA与模式》之策略模式

    <JAVA与模式>之策略模式 在阎宏博士的<JAVA与模式>一书中开头是这样描述策略(Strategy)模式的: 策略模式属于对象的行为模式.其用意是针对一组算法,将每一个算法 ...