[eluser]aquary[/eluser]
I have been using my own custom MY_model, which contains basics DB functions like create(), update(), delete() and other stuffs, for a while. All of them accept $cfg to specify the condition and setting for the query, which is parsed and set by the prepare() function inside the MY_model. To call the function, I'd write a code like this in the controller:
Code:
// this would delete all data with parent=3 and status=1 in the default table of the model
$cfg->where=array('parent'=>3, 'status'=>1);
$this->accounts->delete($cfg);
// or use this to delete data in another table
$this->accounts->delete($cfg, 'TABLE_NAME_HERE');
Lately, I'm quite curious about the code. The $cfg is easy for me to do the same stuff without writing similar functions with minor different (eg. delete_account($id), delete_unactive_accounts(), delete_xxx_accounts()). But in other way, I'm quite bored of setting $cfg every time to delete or select data. Many times I'd forget to reset the $cfg and send a wrong setting, or forget to set the condition, which resulted in all rows in a table updated with the same values.
For everyone else, how you handle this kind of functions? Are you using "One function to rules them all", or "Write a right function for a right task" ?