![]() |
CI and class - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: CI and class (/showthread.php?tid=36324) |
CI and class - El Forum - 11-28-2010 [eluser]natefons[/eluser] if i want to build a class with constructors, inspectors and methods and what not. that i can create multiple instances of that class class pen { default constructor inspectors methods } $data= array('id'=>3,'make'=>'papermate'); $bic=new pen($data); $data= array('id'=>5,'make'=>'ballpoint'); $n=new pen($data); bic->getmake(); //papermate $n->getmake(); //ballpoint (sorry if this syntax isnt perfect..just wanted an example to show what i wanted) how can i do this with CI...i read up on the user guide, and a library seems like my best bet...am i right? if not what should i do? CI and class - El Forum - 11-29-2010 [eluser]jalalski[/eluser] If you want the objects to have all the facilities of Models, then you will have to make them a Model, otherwise a Library will be fine. Often what I do is create collections and objects in the same file. e.g. Code: class Books_model extends Model { the collection has all the facilities of the Model and can create etc Book's. CI and class - El Forum - 11-29-2010 [eluser]natefons[/eluser] so do i load book class inside book model? assume i have 3 books. Harry potter, Twilight. how will i do: $book1= new book("Harry potter"); $book2= new book("Twilight"); will it go in the controller? or the model |