MY_Model Base CRUD Model - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: MY_Model Base CRUD Model (/showthread.php?tid=24361) |
MY_Model Base CRUD Model - El Forum - 04-04-2010 [eluser]rkjaer[/eluser] [quote author="ciKD" date="1270397463"]This is a very nice MY_Model, but can it handle join somehow? Or did I just miss the logic how to use it with joins?[/quote] Yes you can in a fairly easy way Below is an example usin MY_Models "get_all" with a join query and ordering from CI's active records. Note that it ends up with calling its parent (get_all). Code: function get_all() MY_Model Base CRUD Model - El Forum - 04-04-2010 [eluser]ciKD[/eluser] Thanks for quick reply! So this MY_Model itself does not support a special join param in its methods but I can add the join(s) by myself and let MY_Model get the data. You named the function function get_all(), but I can name it anything i like, right? Code: function whatever_i_want(params) MY_Model Base CRUD Model - El Forum - 04-04-2010 [eluser]rkjaer[/eluser] [quote author="ciKD" date="1270400584"]Thanks for quick reply! So this MY_Model itself does not support a special join param in its methods but I can add the join(s) by myself and let MY_Model get the data. You named the function function get_all(), but I can name it anything i like, right?[/quote] You're welcome! Exactly. I see you got the idea already You can name them just as you like and call whatever parent you need MY_Model Base CRUD Model - El Forum - 04-04-2010 [eluser]darkhouse[/eluser] If you're going to do that, you don't need to call parent - not that it makes much difference. You can do this: Code: function whatever_i_want(params) The result will be the same. I only use parent:: when I'm overriding a method like rkjaer wrote. Since you're calling it whatever you want, you can use $this-> instead of parent:: MY_Model Base CRUD Model - El Forum - 04-04-2010 [eluser]rkjaer[/eluser] [quote author="darkhouse" date="1270401669"]If you're going to do that, you don't need to call parent - not that it makes much difference. You can do this: Code: function whatever_i_want(params) The result will be the same. I only use parent:: when I'm overriding a method like rkjaer wrote. Since you're calling it whatever you want, you can use $this-> instead of parent::[/quote] Oh, yes. Sorry - you're so right about that. MY_Model Base CRUD Model - El Forum - 04-04-2010 [eluser]Unknown[/eluser] Hello. I included this function on your model, it works for MYSQL version 5.x It fetch the primary key, without have to change it, I call it on __construct Code: private function _fetch_pkey() MY_Model Base CRUD Model - El Forum - 04-04-2010 [eluser]ciKD[/eluser] Looks interesting! With a similar approach, could you write a version which fetches the column-names of the table to an array so a function to (auto)validate a given order_by field could be added, using an in_array() check? MY_Model Base CRUD Model - El Forum - 05-10-2010 [eluser]ed_ball[/eluser] All links in original post now seem to be broken - what's the deal? MY_Model Base CRUD Model - El Forum - 05-10-2010 [eluser]michalsn[/eluser] Check here: https://bitbucket.org/jamierumbelow/codeigniter-base-model/src MY_Model Base CRUD Model - El Forum - 05-11-2010 [eluser]ed_ball[/eluser] Thanks. I've installed this now but having problems with the table property in MY_Model conflicting with the native CI table method. The workaround I am employing currently is to 'reset' $this->table to 'new CI_table' before setting table heading etc as otherwise the following error occurs "Call to a member function set_heading() on a non-object...". Could this be considered a bug in the code or am I suffering from a lack of understanding of OOP? |