Active Record Conflict |
Hello
Are there any way to prevent Active record query builder conflicts. Imagine, In my controller, I am using Model "A" that uses Active record query builder. Between this, i want to use a library that it also uses Active record query builder to make it's query, But the problem is here, what i will have in the final, is a mixture of both of them. what should i do to solve that?
Maybe this can help you
http://www.codeigniter.com/user_guide/da...ry-builder
Don't create this "mixture". What you have in model A shouldn't affect model B.
(09-30-2015, 01:41 PM)Anisi Wrote: Hello This is because the Query Builder module extends the DB Driver which is typically a single instance for each DB connection. I have hacked a new library QB that sits on top of the DB driver. I'd like to see this make it in to CI officially someday, but not sure my solution is correct. Create a new library (say Query_builder.php) by copying the query_builder (or active_record in 2.x) code from CI system/database to your application library. Change the class definition to: Code: class Query_builder { and add the following after the instance variable declarations and before the functions are declared: Code: protected $DB; This makes the query buillder object behave like a $CI->db by forwarding any un-handled functions to the CI db instance using the magic __get and call_user_func_array(). Each query builder instance has independent state variables and there are no more conflicts. Back in the 2.x days there was a version of active_record that was posted that did this internally, but I think my solution is more elegant with fewer code changes. Under 2.x you have to copy and modify a _delete() function from the driver, but not necessary in 3.0. To use it: Code: // db should be already loaded, but just in case... |
Welcome Guest, Not a member yet? Register Sign In |