-3

In this statement from codeigniter

$this->db->select('')

Are we saying,

From the current model object, find the object called 'db' then run the function in 'db' called select?

Thanks

Ben_hawk
  • 2,476
  • 7
  • 34
  • 59
  • 1
    [Object Oriented Programming](http://us3.php.net/manual/en/language.oop5.php) – Nikola K. Jul 10 '12 at 22:09
  • possible duplicate of [Reference - What does this symbol mean in PHP?](http://stackoverflow.com/questions/3737139/reference-what-does-this-symbol-mean-in-php) – Explosion Pills Jul 10 '12 at 22:10

2 Answers2

2

$this is a reference to the current object.
db is a property of whichever object $this represents.
select() is a method of the db object.

You use -> in an object oriented context to access methods and properties of an object.

Edit
To answer your question in the comments, we need to clarify the terminology being used. A class has methods (functions) and properties (variables).

In this case, db is an object (you can tell because it has a select method). But in the context of the object represented by $this, it is a property of the object.

Steven Mercatante
  • 24,757
  • 9
  • 65
  • 109
  • so am i right in thinking db is an object of the $this object. I understand $this->myMethod(); calls a method inside the object by theres a 3rd level here - $this->db->select('') - – Ben_hawk Jul 10 '12 at 22:25
0

$this->db->select('mytable')

would result in the follwing MySQL query:

'SELECT * FROM mytable'

Here is a link to the Active Record docs for CodeIgniter.

Drewness
  • 5,004
  • 4
  • 32
  • 50