CodeIgniter Forums
MY_Model Base CRUD Model - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived Libraries & Helpers (
+--- Thread: MY_Model Base CRUD Model (/showthread.php?tid=24361)

Pages: 1 2 3 4 5 6

MY_Model Base CRUD Model - El Forum - 05-11-2010

[eluser]Jamie Rumbelow[/eluser]
It was a bug... but a while ago. Take a look at the source, it should be protected $_table.


MY_Model Base CRUD Model - El Forum - 05-27-2010

I'm trying to use the version 1.1.1, but i'm having some dificulties:

- how I can retrieve just 2 columns using MY_Model?
For example, a table with 15 fields but I want to retrieve only 2 fields: name and date. How i can retrieve just these 2 fields? How i can format the date field with the format "%Y-%m-%d %H:%i:%s"?

-Can I use more than 1 argument to create a WHERE condition when I use methods like "get_by()" or "get_many_by()"?

This is a great tool. Congratulations. And sorry about my english.

MY_Model Base CRUD Model - El Forum - 05-28-2010

[eluser]Jamie Rumbelow[/eluser]
Hi Mafagafo,

You'll need to create your own methods to do complex things like this. You can filter out this stuff by calling ActiveRecord methods on CodeIgniter's database class:

$this->db->select('username, email');
$this->users->get_by('id', 1);


MY_Model Base CRUD Model - El Forum - 06-03-2010

Hi, I need some advice on how to organize my models when using base models like the one you created.

Suppose I want to have a reusable cms/blog (something that allows me to create articles, comments, categories, links, tags, etc etc)

Would you create one model for each? Example: Article_m, Comment_m, Category_m, so you can have the table name auto-fetched most of the times?

Or one big model that handles everything?

If each Article has many Comments.. Which model should handle the articles_comments table? (supposing I want to have this sepparate table. Or just imagine any many-to-many situation)

Thanks in advance!

MY_Model Base CRUD Model - El Forum - 06-03-2010

[eluser]Jamie Rumbelow[/eluser]
This is more of a generic MVC question, and always the former! Keep things as separated as possible. When dealing with relationships, try to have a "parent" and "child" (in your case, parent is Article), and have the parent handle the relationships.

Hope this helps,


MY_Model Base CRUD Model - El Forum - 06-03-2010

It's just that I never see things like subdirectories inside /models. All the libraries I have seen, they always come with 1 big library, and 1 big model.

Well thanks for your answer, I guess I have to try this method (separate everything) and see what happens.

MY_Model Base CRUD Model - El Forum - 08-02-2010

It seems that there's also another good MY_Model option developed by
which is available to reiview at:

Just wondering why not merge the good of both worlds? Croxton's got good support
for more complex operations like joins.


MY_Model Base CRUD Model - El Forum - 08-10-2010

[quote author="rkjaer" date="1267910407"]Anyone managed to make this support multiple databases? I need this solution for my current project, but had no luck yet. Unfortunately the author Jamie does not have time for this suggested feature Sad[/quote]

I'm not sure if you are still looking for an answer but you might want to take a look at this link. He has implemented a My_Model where you can use multiple databases. The link is:

MY_Model Base CRUD Model - El Forum - 05-03-2012

I am having HUGE problems with memory when I try to use the functions get_many, get_many_by and get_all

here's my controller code
// List all addresses of a given user
public function index( $user_id = NULL )
  $this->load->model('addresses_model', 'addresses');
  $addr = $this->addresses->get_many_by( array('user_id' => $user_id) );

  print_r($addr); //debug

in the model
class Addresses_model extends MY_Model {

public function __construct()
  // Load base construct

The error i get is
Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 40 bytes) in
/application/models/addresses_model.php on line 20

For the record. I tried with $this->db->get() and everything works perfectly. The problem appears just using MY_Model.php
What can I do? Please help.