Home >Backend Development >PHP Tutorial >Analysis of the underlying principles of CodeIgniter's coherent operation, codeigniter underlying_PHP tutorial

Analysis of the underlying principles of CodeIgniter's coherent operation, codeigniter underlying_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 08:52:141041browse

Analysis of the underlying principles of CodeIgniter's coherent operations, codeigniter's underlying principles

This article analyzes the underlying principles of CodeIgniter's coherent operations. Share it with everyone for your reference, the details are as follows:

PHP oop coherent operation principle

The

-> symbol actually passes the object pointer. Maybe that's not the right thing to say.

However, we can understand it this way.

Not much to say. Put the code.

Common usage:

<&#63;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();
&#63;>

Consistent usage:

<&#63;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();
&#63;>

Did you see it?

Connected. You can string operations together.

Looks much more intuitive. It’s also much easier when reading code.

All operations in the class return a pointer.

$this.

It is equivalent to the object you initialized $oktest

So the following operations can be continued.

Try to remove

from each operation
return $this

You will see an error message.

Example:

<&#63;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();
&#63;>

Readers who are interested in more CodeIgniter related content can check out the special topics of this site: "codeigniter introductory tutorial", "CI (CodeIgniter) framework advanced tutorial", "php excellent development framework summary", "ThinkPHP introductory tutorial", "Summary of Common Methods in ThinkPHP", "Introduction Tutorial on Zend FrameWork Framework", "Introduction Tutorial on PHP Object-Oriented Programming", "Introduction Tutorial on PHP MySQL Database Operation" and "Summary of Common PHP Database Operation Skills"

I hope this article will be helpful to everyone’s PHP program design based on the CodeIgniter framework.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1127867.htmlTechArticleAnalysis of the underlying principles of CodeIgniter's coherent operations, codeigniter's underlying principles. This article analyzes the underlying principles of CodeIgniter's coherent operations. Share it with everyone for your reference, the details are as follows: php oop coherent...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn