Objects from custom classes - 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: Objects from custom classes (/showthread.php?tid=13633) |
Objects from custom classes - El Forum - 11-30-2008 [eluser]kRON[/eluser] Hey everyone! Just started using CI today and having a blast. There's one thing I'm bugged though and I can't really find it in the user guides. I want to know how do you hook your custom classes with, let's say, your model classes? To be more specific, I'm trying to make my Twitter model that would cache and parse my twitter feed. Specifically, to make my life easier, I'd like to have the Twitter model return Twit objects that contain all the data. I'm not that versed with OOP in PHP, so this is, kinda, how I've imagined everything Twitter model Code: class Twitter extends Model { Twit class Code: class Twit { Controller Code: $this->load->model('Twitter'); View Code: <?php foreach ($twitters as $twit): ?> Can anyone help me explain where and how would I create the Twit class as to make it available for creating objects within the Twitter model? I hope I'm not thinking about doing this the wrong way and that something like this is possible - is there a better practice? Objects from custom classes - El Forum - 11-30-2008 [eluser]crumpet[/eluser] The way i deal with this is to create a library called lib_twit.php in that file there are two class declarations Code: class lib_twit{ Code: $this->load->library('lib_twit'); Objects from custom classes - El Forum - 11-30-2008 [eluser]kRON[/eluser] So I could do it with multiple classes per document? I thought about it, but seemed very unOOPish ! Right, thanks, I'll have a jab at it right away. Objects from custom classes - El Forum - 11-30-2008 [eluser]kRON[/eluser] Thanks crumpet, works like a charm! So I guess that wraps it up, factory patterns are the way to go. Just in case someone bumps into the same problem, here is my quick 'n dirty test Model forwarding custom objects Code: class Twitter extends Model { |