A "User's Guide" to Jamie Rumbelow's MY_Model library |
[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/u...s-my_model
[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.
[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.
[eluser]Mauricio de Abreu Antunes[/eluser]
I know. Anyway thanks! I'll add some methods in this model and post here.
[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!
[eluser]theshiftexchange[/eluser]
Is there any way to do simple joins with this? Or do I need to re-write those functions?
[eluser]theshiftexchange[/eluser]
found the answer myself - incase anyone is looking for it- use a "before_get" callback, and run a join in there.
[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)
[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 |
Welcome Guest, Not a member yet? Register Sign In |