CodeIgniter連貫操作的底層原理分析,codeigniter底層_PHP教程

來源:互聯網
上載者:User

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


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

php oop連貫操作原理

->符號其實是傳遞對象指標的。或許這麼說是不對的。

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

不多說。放代碼。

普通用法:

<?phpclass 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();?>

連貫用法:

<?phpclass 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();?>

看到了沒有。

連起來了。可以把操作串起來。

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

類裡面操作都返回了一個指標。

$this.

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

所以下面的操作可以連續起來。

試著去掉每個操作裡的

return $this

你將會看到錯誤提示。

例子:

<?phpclass 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();?>

更多關於CodeIgniter相關內容感興趣的讀者可查看本站專題:《codeigniter入門教程》、《CI(CodeIgniter)架構進階教程》、《php優秀開發架構總結》、《ThinkPHP入門教程》、《ThinkPHP常用方法總結》、《Zend FrameWork架構入門教程》、《php物件導向程式設計入門教程》、《php+mysql資料庫操作入門教程》及《php常見資料庫操作技巧匯總》

希望本文所述對大家基於CodeIgniter架構的PHP程式設計有所協助。

http://www.bkjia.com/PHPjc/1127867.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1127867.htmlTechArticleCodeIgniter連貫操作的底層原理分析,codeigniter底層 本文分析了CodeIgniter連貫操作的底層原理。分享給大家供大家參考,具體如下: php oop連貫...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.