Welcome Guest, Not a member yet? Register   Sign In
Model objects linked directly to db tables?
#1

[eluser]coldscooter[/eluser]
I would like to treat my models as objects that are directly linked to database.

So I could something like this in my controllers:

//To save a new password
$this->load->model('user');
$this->user->password = 'new_password';
$this->user->save();


Is there a library out there that would do something like this for me?

#2

[eluser]WanWizard[/eluser]
Lots.

You can either go for a lightweight MY_Model solution that your models can extend. Jamie Rumbelow created a good one.

If you're looking for more advanced features like for example relations (so you can easily fetch all groups related to a user for example), you need to look at an ORM.

Search here and you'll probably find a few...
#3

[eluser]coldscooter[/eluser]
I definitely want to be able to work with relationships between the models.

Any recommended ORM library i should look into?
#4

[eluser]WanWizard[/eluser]
You'll find the one I would recommend in my signature. But you could argue I'm biased. Wink
#5

[eluser]coldscooter[/eluser]
I'm trying to use DataMapper, and have followed the setup instructions, but I'm getting "Table 'my_table.DataMappers' doesn't exist"


My model looks like this:

class user extends DataMapper {
var $table = 'user';

function __contruct () {
parent::__contruct();
}
}


Could it be that DataMapper doesn't work with the most recent CI?
#6

[eluser]Aken[/eluser]
Check your construct spelling.
#7

[eluser]WanWizard[/eluser]
As long as you have installed the bootstrap in your index.php, Datamapper 1.8.2.1 (the latest version) works fine with CI 2.1.

There are issues with the 'reactor' version, due to large changes in the core, so that is not supported at the moment. I'm waiting until that stabilizes before I start working on that issue.




Theme © iAndrew 2016 - Forum software by © MyBB