Welcome Guest, Not a member yet? Register   Sign In
CI and class
#1

[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?
#2

[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 {
  ...
}
class Book {
  var $title;
  var $isbn;
  ...
}

the collection has all the facilities of the Model and can create etc Book's.
#3

[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




Theme © iAndrew 2016 - Forum software by © MyBB