欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

CodeIgniter連貫操作的底層原理分析

 更新時間:2016年05月17日 11:56:40   作者:yanhui_wei  
這篇文章主要介紹了CodeIgniter連貫操作的底層原理,結(jié)合實例形式分析了CodeIgniter中常見的php oop連貫操作實現(xiàn)原理,具有很大的通用性,代碼簡單易懂,需要的朋友可以參考下

本文分析了CodeIgniter連貫操作的底層原理。分享給大家供大家參考,具體如下:

php oop連貫操作原理

->符號其實是傳遞對象指針的?;蛟S這么說是不對的。

但是,我們可以這么的理解。

不多說。放代碼。

普通用法:

<?php
class test
{
 public $a='';
 public $b='';
 public function actiona() {
  $this->a="hello";
  return $this;
 }
 public function actionb() {
  $this->b="world";
  return $this;
 }
 public function actionc() {
  echo $this->a." ".$this->b;
 }
}
$oktest=new test();
$oktest->actiona();
$oktest->actionb();
$oktest->actionc();
?>

連貫用法:

<?php
class test
{
 public $a='';
 public $b='';
 public function actiona() {
  $this->a="hello";
  return $this;
 }
 public function actionb() {
  $this->b="world";
  return $this;
 }
 public function actionc() {
  echo $this->a." ".$this->b;
 }
}
$oktest=new test();
$oktest->actiona()->actionb()->actionc();
?>

看到了沒有。

連起來了??梢园巡僮鞔饋怼?/p>

看起來直觀多了。閱讀代碼時也輕松了很多。

類里面操作都返回了一個指針。

$this.

他等價于你初始化的那個對象 $oktest

所以下面的操作可以連續(xù)起來。

試著去掉每個操作里的

return $this

你將會看到錯誤提示。

例子:

<?php
class sql{
 public $select;
 public $from;
 public $where;
 public $order;
 public $limit;
 public function from($_from='FROM test') {
 $this->from=$_from;
 return $this;
 }
 public function where($_where='WHERE 1=1') {
 $this->where=$_where;
 return $this;
 }
 public function order($_order='ORDER BY id DESC') {
 $this->order=$_order;
 return $this;
 }
 public function limit($_limit='LIMIT 0,30') {
 $this->limit=$_limit;
 return $this;
 }
 public function select($_select='SELECT *') {
 $this->select=$_select;
 return $this->select." ".$this->from." ".$this->where." ".$this->order." ".$this->limit;
 }
}
$sql =new sql();
echo $sql->from()->where()->order()->limit()->select();
?>

更多關(guān)于CodeIgniter相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《codeigniter入門教程》、《CI(CodeIgniter)框架進階教程》、《php優(yōu)秀開發(fā)框架總結(jié)》、《ThinkPHP入門教程》、《ThinkPHP常用方法總結(jié)》、《Zend FrameWork框架入門教程》、《php面向?qū)ο蟪绦蛟O(shè)計入門教程》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總

希望本文所述對大家基于CodeIgniter框架的PHP程序設(shè)計有所幫助。

相關(guān)文章

最新評論