Welcome Guest, Not a member yet? Register   Sign In
Instantiate multiple library and put them into an array
#1

[eluser]Unknown[/eluser]
Hi to all,
i’m not sure if what I have code is correct or may be much more clean.

I have a library CARDS where in the constructor I can pass one parameter (id). Then, the constructor, if id param is present, make a query to set some internal variables.

In another library PLAYER i retrive an array of ids, and want to have an array of CARD object.

This works for me ... but i would like to know if it's a clean code ... Is this the best way to do?

in the PLAYER lib I have something like this:

Code:
foreach( $card_ids as $value )
            {
                $this->CI->load->library('Card', array('id' => $value['card_id']), $value['card_id']);
                $cards[] = $this->CI->$value['card_id'];
            }
return $cards;


Now, $cards contents all the CARD object.

Repeat, works great ... but I'm curious if there is a better way to do
what I want to do... I never used the loader class in this way before.

What about memory usage? Should I be careful ?

Thanks




Theme © iAndrew 2016 - Forum software by © MyBB