where to put database helpers (driver, active record, or helper) |
[eluser]a&w[/eluser]
I perused the mysqli_driver and DB_active_rec classes (as well as the user guide and forum of course). I have repetitive needs to prepare a query with orderby, sortby and other where conditions. I wasn't quite sure where to stick these "helpers". Should I just make my own helper class, or extend either the driver or active record class? My first impressions: HELPER pros: Don't "mess" with any core classes whatsoever cons: Will need to load the helper class ACTIVE RECORD pros: Already available to model without loading cons: I'm not sure the strings I'd generate would apply to other db drivers (but not likely use a different driver anyway) MYSQLi DRIVER pros: Already available to model without loading cons: "Messing" with the core class, but if only adding methods shouldn't circumvent future CI releases? So my inclination (at the moment) might be to extend the mysqli_driver.
[eluser]Developer13[/eluser]
I'm not quite sure why you are not just considering building that functionality into your models... CI's database class more than supports what you are trying to do...
[eluser]a&w[/eluser]
I didn't see where there's anything for sort or order by. Also, I'll have multiple models which could use a helper utility to build the query. Since I'd being using similar code multiple times and since the existing class(es) don't have all the functions I want I thought to extend or provide a helper in some way.
[eluser]a&w[/eluser]
Ok, I used MY_Model. I'll post what I did in case someone else stumbles onto this thread: Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); and Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Two semi-related links: extend Model class Extending the core: MY_Model |
Welcome Guest, Not a member yet? Register Sign In |