Welcome Guest, Not a member yet? Register   Sign In
Meet CodeIgniter MY_Model
#17

Just some feedback based on a quick look at what you have so far:

You should probably change the name and visibility of the $table property. It may not happen very often (and probably shouldn't happen at all), but $this->table could refer to the CI HTML Table library ( http://www.codeigniter.com/userguide3/li...table.html ). A getter for the property could also utilize the _fetch_table() method when the property is not set (or the method could be modified to become the getter method). I'm guessing that the issues you're seeing trying to use that method from within other methods has something to do with the combination of the visibility of the method and the use of get_class($this), but I really can't help much on that without doing some testing.

You're loading the inflector helper in the constructor, then again in the _get_table_name() method. You use it in 2 or 3 other methods (via the singular() function), so removing it from the constructor would require adding it to those methods, or you could just remove it from the _get_table_name() method.

In the fields() method, rather than imploding the input you can pass an array into the select method. After all, the select() method is going to explode it if you pass a string.

You may want to use a protected method to set the timestamps in your add_created(), add_updated(), and add_deleted() methods which allow the fields to be different types. Otherwise, it's likely that each of these methods would have to be modified by anyone attempting to use the model with a database other than MySQL. I'd recommend looking at how Bonfire does this in the modified_on()/created_on() methods using the set_date() method. https://github.com/ci-bonfire/Bonfire/bl..._Model.php
Reply


Messages In This Thread
Meet CodeIgniter MY_Model - by Avenirer - 02-20-2015, 02:47 AM
RE: Meet CodeIgniter MY_Model - by Rufnex - 02-20-2015, 03:24 AM
RE: Meet CodeIgniter MY_Model - by spjonez - 02-20-2015, 05:55 AM
RE: Meet CodeIgniter MY_Model - by dmyers - 02-20-2015, 08:58 AM
RE: Meet CodeIgniter MY_Model - by Avenirer - 02-25-2015, 02:50 AM
RE: Meet CodeIgniter MY_Model - by Avenirer - 02-25-2015, 02:52 AM
RE: Meet CodeIgniter MY_Model - by spjonez - 02-25-2015, 05:57 AM
RE: Meet CodeIgniter MY_Model - by Avenirer - 02-25-2015, 06:28 AM
RE: Meet CodeIgniter MY_Model - by spjonez - 02-25-2015, 07:07 PM
RE: Meet CodeIgniter MY_Model - by Avenirer - 02-26-2015, 01:54 AM
RE: Meet CodeIgniter MY_Model - by Avenirer - 02-26-2015, 05:46 AM
RE: Meet CodeIgniter MY_Model - by spjonez - 02-26-2015, 06:55 PM
RE: Meet CodeIgniter MY_Model - by Avenirer - 02-26-2015, 11:51 PM
RE: Meet CodeIgniter MY_Model - by Avenirer - 02-27-2015, 12:35 AM
RE: Meet CodeIgniter MY_Model - by spjonez - 03-03-2015, 04:36 PM
RE: Meet CodeIgniter MY_Model - by Avenirer - 03-04-2015, 06:57 AM
RE: Meet CodeIgniter MY_Model - by mwhitney - 03-06-2015, 11:27 AM
RE: Meet CodeIgniter MY_Model - by spjonez - 03-09-2015, 05:41 AM
RE: Meet CodeIgniter MY_Model - by ivantcholakov - 03-09-2015, 12:52 PM
RE: Meet CodeIgniter MY_Model - by spjonez - 03-11-2015, 06:27 AM
RE: Meet CodeIgniter MY_Model - by san1020 - 03-12-2015, 05:14 AM
RE: Meet CodeIgniter MY_Model - by Avenirer - 03-16-2015, 03:14 AM
RE: Meet CodeIgniter MY_Model - by ircdirk - 03-25-2015, 06:52 AM
RE: Meet CodeIgniter MY_Model - by dgvirtual - 09-25-2016, 01:06 AM
RE: Meet CodeIgniter MY_Model - by Avenirer - 09-27-2016, 11:26 PM
RE: Meet CodeIgniter MY_Model - by dgvirtual - 09-28-2016, 12:00 AM
RE: Meet CodeIgniter MY_Model - by Avenirer - 09-28-2016, 12:17 AM



Theme © iAndrew 2016 - Forum software by © MyBB