![]() |
[SOLVED] Is this the correct way of using __set() in a model? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: [SOLVED] Is this the correct way of using __set() in a model? (/showthread.php?tid=4990) |
[SOLVED] Is this the correct way of using __set() in a model? - El Forum - 12-29-2007 [eluser]Maarten B[/eluser] Hi all, I'd like to use PHP5's __set() magic function in a model. The code below doesn't work; the $this->db is unknown, probably because the model doesn't get properly intialised: Code: class PersonAccess extends Model When I add a default block to the switch statement, basically saying: "if this class doesn't have the property, try the parent class", it works. Code: class PersonAccess extends Model My question is: is this Code: parent::Model()->$name = $value; I mean, I don't get errors, everything seems to work, I just want to be sure. Other attempts like Code: Model()->$name = $value; //doesn't work Much thanks in advance! Maarten [SOLVED] Is this the correct way of using __set() in a model? - El Forum - 12-30-2007 [eluser]alpar[/eluser] why Code: parent::Model()->$name = $value; why wouldn't $this->$name do ? There is no point to assign a the value of a property to a parent since properties are inherited. [SOLVED] Is this the correct way of using __set() in a model? - El Forum - 12-30-2007 [eluser]Maarten B[/eluser] [quote author="alpar" date="1199029548"] why wouldn't $this->$name do ? There is no point to assign the value of a property to a parent since properties are inherited.[/quote] Alpar, Code: $this->$name = $value; I made it way too difficult and forgot about the inheritance. Thanks a lot for replying and reminding me! ;-) Maarten |