Welcome Guest, Not a member yet? Register   Sign In
ActiveRecods x Mapping Fields

[eluser]Marcus Cavalcanti[/eluser]
Hi CI People,

I have one question about of the use of models and active records simultaneously.

Ih i have a entity called "user" and the "user" entity have 5 properties like a: id, user, password, name, status.

In my model i would have something like a:

class User extends Model {
  var $id;
  var $login;
  var $pass;
  var $name;  
  var $status;
    function getUserByName () {
     $query = $this->db->getwhere('user', array('name' => $name));
      return $user;


The problem is when i using the result of model in my controller, the properties of model the is equal the name of fields of table user in my database and is not right. The correct is mapping the fields through the model and if the name of the fields database has change, the unique place that i change is the model, not the controllers.

I thought to solve this using beans (getters and setters methods), like a suggest in this thread: http://ellislab.com/forums/viewthread/45754/

My idea is return the objects (beans) that represents my fields in database.

Anyone knows if the CI have's a ellegant solution for this?

Theme © iAndrew 2016 - Forum software by © MyBB