Iterate a model's attributes within the model? |
[eluser]Dam1an[/eluser]
You can read about magic methods here The idea behind the __get/__set methods, is it provides a nice way for manipulating private variables, so you could do something like Code: private $attributes = array(); You could then just loop through the array as before in the get method
[eluser]Colin Williams[/eluser]
Does get_object_vars($this) not do it for you? I've never tried it that way..
[eluser]Michael McCabe[/eluser]
Well I still don't know which method to choose but I now have lots more to choose from! :ahhh: I had heard of magic methods but didn't realise they were called that. Think I'm going to go with that method. Thanks again. The high praise for this community is definitely deserved. :-)
[eluser]Michael McCabe[/eluser]
[quote author="Colin Williams" date="1241915541"]Does get_object_vars($this) not do it for you? I've never tried it that way..[/quote] I got all excited then and tried this but it results in exactly the same result as my first post. EVERYTHING codeigniter ends up in the variable as I presume this refers to not just the class your in but every class it is extended from. Or something like that, I'm only slightly proficient in php and a noob to frameworks and codeigniter. I just tried this - Code: <?php It resulted in a HUGE page of objects being printed to the page and timed out before it had even finished.
[eluser]Dam1an[/eluser]
I'm assuming you still get everything, because it gets all the vars for this class, and the class this class extends, and so on, till you get pretty much everything lol
[eluser]Dam1an[/eluser]
I'm assuming you still get everything, because it gets all the vars for this class, and the class this class extends, and so on, till you get pretty much everything lol Ooops, double post (It just reloaded the page the first time without having submitted, which happens a lot, but this is the first time its double posted)
[eluser]peterphp[/eluser]
I found this code on another forum, it seems to solve the problem by excluding "_parent_name": Code: function get() Found this snipplet here. Seems to me like the 'right' way to do it :-) |
Welcome Guest, Not a member yet? Register Sign In |