7

I've seen people use this piece of code and I'm trying to understand what it does because I don't see it in any of the codeigniter documenation or in the source code for the database class.

$this->db->ar_orderby
4
  • Adding some context would certainly help Commented Jan 30, 2013 at 20:12
  • 1
    From what my noobnes tells me, $this is a special variable meant to refere a class and the -> means sort of get/use in this case, I would presume db is actually a variable to hold database resource and as a variable was declared as $db but if you are using $this-> you can't use the $ sign... I started learning OOP just about yesterday, and that is all that I know :) Commented Jan 30, 2013 at 20:13
  • db is probably instantiated in the constructor. $this->db would get you that db instance within any functions in that class. Commented Jan 30, 2013 at 20:15
  • After some searching, I'm fairly convinced that ar_orderby() is a deprecated function. You should use $this->db->order_by(); Commented Jan 30, 2013 at 20:19

4 Answers 4

8

This is an array that holds order by columns..

There should be no reason to use this property directly. Instead call $this->db->order_by('column') which appends to the array automatically.

  • defined in system/database/DB_active_rec.php Line 42
  • appended to in method CI_DB_active_record::order_by Line 856
  • used to generate SQL in CI_DB_active_record::_compile_select Line 1781
Sign up to request clarification or add additional context in comments.

Comments

3

You mean

http://phpxref.com/xref/codeigniter/system/drivers/DB_active_record.php.source.html#l781

It allows you to specify the order by.

Comments

3

It still makes sense to use this in the way below -

if (!count($this->db->ar_orderby)) {
    $this->db->order_by($this->order_by );
}

It basically means - If an order is not already set by db library when this method was called, use this. Prevents calling of "order by" twice.

Comments

0

You can replace these lines:

if (!count($this->db->ar_orderby)) {
    $this->db->order_by($this->order_by );
}

with:

if(!count($this->db->order_by($this->order_by))) {
    $this->db->order_by($this->order_by);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.