CodeIgniter Forums
ar_orderby has changed to qb_orderby - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forum-6.html)
+--- Forum: Issues (https://forum.codeigniter.com/forum-19.html)
+--- Thread: ar_orderby has changed to qb_orderby (/thread-1021.html)



ar_orderby has changed to qb_orderby - dollardad - 02-06-2015

When checking to see if a db->order_by has been set

If ( ! count( $this->db->ar_orderby ) ) { /* */ }

php notice message Undefined property: CI_DB_mysqli_driver::$ar_orderby

Looking through I see it has been changed to qb_orderby

when running

If ( ! count( $this->db->qb_orderby ) ) { /* */ }

we get error message

Fatal error: Cannot access protected property CI_DB_mysqli_driver::$qb_orderby

Any clues how we can add a conditional statement to see if an order_by has been set ??


RE: ar_orderby has changed to qb_orderby - Avenirer - 02-06-2015

when was an ar_orderby in the past? Don't remember seeing it in the documentation...


RE: ar_orderby has changed to qb_orderby - mwhitney - 02-06-2015

You basically have three options:
- track it yourself,
- use get_compiled_select() and check the result for an order by statement, or
- modify your database driver to give you a method to check qb_orderby.


RE: ar_orderby has changed to qb_orderby - dollardad - 02-08-2015

It never was in the documentation, just one of those hidden gems that you got to learn about. Basically it allows you to see if $this->db->orderby() has been set prior to running the query if not then you could set one.

When running print_r prior to running the query on $this->db I can see that ar_orderby has been changed to qb_orderby

How can we now run a check prior to running the db->get to see if db->orderby has been set ?

Many thanks


RE: ar_orderby has changed to qb_orderby - Narf - 02-09-2015

(02-08-2015, 01:18 PM)dollardad Wrote: It never was in the documentation, just one of those hidden gems that you got to learn about.  Basically it allows you to see if  $this->db->orderby() has been set prior to running the query if not then you could set one.

When running print_r prior to running the query on $this->db I can see that ar_orderby has been changed to qb_orderby

How can we now run a check prior to running the db->get to see if db->orderby has been set ?

Many thanks

You can't and you shouldn't.
This is not a gem that you happen to learn about, it hasn't been undocumented for no reason - it's an internal property that you should've never relied on.


RE: ar_orderby has changed to qb_orderby - dollardad - 02-09-2015

@Narf

Thanks for the heads-up on this one and I've changed my code as per. However, methinks you might get a few queries on this one when people move to CI 3 as this "not so little gem" was one of the tricks published on "Codeigniter learning series" by Nettuts.


RE: ar_orderby has changed to qb_orderby - Narf - 02-09-2015

Well, it's really bad if a a tutorials site has suggested using such hacks ... but still, the closest thing that I could suggest as a work-around is Reflection. And even that, I'd discourage.


RE: ar_orderby has changed to qb_orderby - Amr Elsayed - 11-15-2016

Good discussion guys I would thank you, becuase I'm just watching this course by tutsplus and I found this code seems very weird to me. But anyway Joost van veen is one of my favorite lecturers I enjoy learning from him.