![]() |
A "User's Guide" to Jamie Rumbelow's MY_Model library - 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: A "User's Guide" to Jamie Rumbelow's MY_Model library (/showthread.php?tid=48383) |
A "User's Guide" to Jamie Rumbelow's MY_Model library - El Forum - 01-13-2012 [eluser]jmadsen[/eluser] I wasn't sure if this is appropriate, at it links to my own site's blog, but I put together a bit of a "user's guide" for people new to CodeIgniter to encourage them to start using a MY_Model class. Joost van Veen just came out with a great codeigniter.tv video series on creating your own MY_Model, and Jamie's code has been around for a while (and is the basis of the one on PyroCMS), so I didn't want to repeat their efforts. A lot of people recommend Jamie's library to new users, but I think it is a little confusing to them. So my post was simply to walk through all of the functions on it and give an example of each one's use, with the output it gives. Hopefully it will give people a jump-start on using it. So, for better or worse... http://www.codebyjeff.com/blog/2012/01/using-jamie-rumbelows-my_model A "User's Guide" to Jamie Rumbelow's MY_Model library - El Forum - 03-01-2012 [eluser]Mauricio de Abreu Antunes[/eluser] Is there missing join, like or something else in MY_Model? Lemme know if i can add more methods in MY_Model class. A "User's Guide" to Jamie Rumbelow's MY_Model library - El Forum - 03-01-2012 [eluser]CroNiX[/eluser] [quote author="Mauricio de Abreu Antunes" date="1330628036"]Is there missing join, like or something else in MY_Model? Lemme know if i can add more methods in MY_Model class. [/quote] Anything you add to a MY_Controller or a MY_Model will be available to all controllers and models, respectively. So, yes, you can add whatever common methods that you need. A "User's Guide" to Jamie Rumbelow's MY_Model library - El Forum - 03-01-2012 [eluser]Mauricio de Abreu Antunes[/eluser] I know. Anyway thanks! I'll add some methods in this model and post here. A "User's Guide" to Jamie Rumbelow's MY_Model library - El Forum - 03-01-2012 [eluser]Mauricio de Abreu Antunes[/eluser] IMHO, validation must to be in controllers. MY_Model has a validation config. How can i return error messages in Model? I was thinking: 1 - Create a config like Code: //$config_validation[your_table][field] 2 - Create a method in MY_Controller: Code: public function checkValidation ($table, $arr_fields) { PS.: i did not check my code, just for show my ideas! A "User's Guide" to Jamie Rumbelow's MY_Model library - El Forum - 04-24-2012 [eluser]theshiftexchange[/eluser] Is there any way to do simple joins with this? Or do I need to re-write those functions? A "User's Guide" to Jamie Rumbelow's MY_Model library - El Forum - 04-25-2012 [eluser]theshiftexchange[/eluser] found the answer myself - incase anyone is looking for it- use a "before_get" callback, and run a join in there. A "User's Guide" to Jamie Rumbelow's MY_Model library - El Forum - 05-03-2012 [eluser]theshiftexchange[/eluser] I wanted a better solution to mySQL date conversions. In my application, dates are "DD-MM-YYYY" due to the local area. But in mySQL they are "YYYY-MM-DD". So I used callbacks to always flip the date prior to retrial and storage of dates. Code: class Fake_model extends MY_Model Works perfectly for me for single inserts/updates and single/multiple gets. No more date format issues!!! (Havent tested for multiple inserts/updates) A "User's Guide" to Jamie Rumbelow's MY_Model library - El Forum - 05-03-2012 [eluser]theshiftexchange[/eluser] Another idea I'm using - White_list your insert data (after form_validation) so you can just pass the $this->input->post() result and sleep easy at night. Code: class Fake_model extends MY_Model |