CodeIgniter Forums
Undefined property: CI_DB_mysqli_driver::$ar_orderby? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Model-View-Controller (https://forum.codeigniter.com/forumdisplay.php?fid=10)
+--- Thread: Undefined property: CI_DB_mysqli_driver::$ar_orderby? (/showthread.php?tid=61907)



Undefined property: CI_DB_mysqli_driver::$ar_orderby? - 236286 - 05-29-2015

I have a CodeIgniter (version 3)
Message: Undefined property: CI_DB_mysqli_driver::$ar_orderby

Filename: core/MY_Model.php

Line Number: 38

Backtrace:

File: /var/www/html/public/application/core/MY_Model.php
Line: 38
Function: _error_handler

Line Number: 38 and here you are

if (!count($this->db->ar_orderby)) {
$this->db->order_by($this->_order_by);
}
return $this->db->get($this->_table_name)->$method();


RE: Undefined property: CI_DB_mysqli_driver::$ar_orderby? - CroNiX - 05-29-2015

Because it's not "active record" ie "ar_orderby". It's "query builder" in CI3.

https://github.com/bcit-ci/CodeIgniter/blob/develop/system/database/DB_query_builder.php#L143


RE: Undefined property: CI_DB_mysqli_driver::$ar_orderby? - ngangchill - 05-29-2015

replace "ar_orderby" with "qb_orderby" in your MY_Model.php


RE: Undefined property: CI_DB_mysqli_driver::$ar_orderby? - 236286 - 05-30-2015

(05-29-2015, 11:06 PM)ngangchill Wrote: replace "ar_orderby" with "qb_orderby" in your MY_Model.php

I did it and I got a Message: Cannot access protected property CI_DB_mysqli_driver::$qb_orderby


RE: Undefined property: CI_DB_mysqli_driver::$ar_orderby? - 236286 - 05-30-2015

(05-29-2015, 12:33 PM)CroNiX Wrote: Because it's not "active record" ie "ar_orderby". It's "query builder" in CI3.

https://github.com/bcit-ci/CodeIgniter/blob/develop/system/database/DB_query_builder.php#L143

But I didn't understant  what i gonna do in this case


RE: Undefined property: CI_DB_mysqli_driver::$ar_orderby? - mwhitney - 06-01-2015

More than likely, you'll have to rewrite your code to handle this on its own. The ar_orderby property was undocumented, and not meant to be used in your application code. You usually have three options for something like this:
1. Set a property within your model when you add an order by clause (and reset that property when you execute a get/insert/update request).
2. Use the get_compiled_select() method to get the generated SQL and check for the order by clause there.
3. Write your code in a way that makes tracking the addition of an order by clause unnecessary.