• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Loading multiple instances of library

#1
Hi all!

It's my first post, so I hope I found the right section for this! Big Grin

I am using to OOPHP where I could define something like:

PHP Code:
$people = array();
$people[] = new Person("John""Smith"43);
$people[] = new Person("Mike""Red"19);
$people[] = new Person("Rose""Blue"54);
$people[] = new Person("Lily""White"22);
my_db_function($people); 

Which would pass all my instances of Person to my db function.

Now, I understnad in CI rather than using the 'new' keyword I am meant to store my Person class in the /libraries directory and use $this->load->library('Person') (or $this->load('Person') ) and then refer to the object as $this->person->...

My problem is that if I have something like:

PHP Code:
$input_people = .. //Some array containing a range of people received as input from user

$this->load->library('Person');

$people = array();

foreach(
$input_people as $person) {

  
$this->person->name $person->name;
  
/*etc for all properties */

  
$people[] = $this->person;  



Each time the loop runs it updates all previous instances of 'person'.

The only solution I found is to call unserialize(serialize($this->person)) before adding it to the people array. Is there a better way of doing this?
Reply

#2
http://forum.codeigniter.com/thread-420.html
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.