CodeIgniter Forums
Using a model multiple times. - 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: Using a model multiple times. (/showthread.php?tid=47453)



Using a model multiple times. - El Forum - 12-09-2011

[eluser]Unknown[/eluser]
I may be being a bit dumb here... but anywho...

I have a category model which contains your average CRUD functionality and data related properties.
There is a method called load() which takes a category identifier to load the requested category.
However, when I'm trying to load the category parent from within eg;
Code:
....
public function load( $id )
{

   // get category and set info...

   if( !is_null( $record->parent_id ) )
   {
       $this->_parent = $this->category->load( $parent_id );
   }

}
...
it returns
Code:
Admin_Category Object
(
    .....
    [_parent_id:protected] => 6
    [_parent:protected] => Category Object
        (
            .....
            [_parent_id:protected] =>
            [_parent:protected] => Category Object
*RECURSION*
        )

)
When I use the standard $obj = new Obj(); method, everything is returned fine, like so;
Code:
Admin_Category Object
(
    .....
    [_parent_id:protected] => 6
    [_parent:protected] => Category Object
        (
            [_id:protected] => 6
            .....
            [_parent_id:protected] => 10
            [_parent:protected] => Category Object
                (
                    [_id:protected] => 10
                    .....
                    [_parent_id:protected] =>
                    [_parent:protected] =>
                )

        )

)

I guess my question, is is there a way of getting $this->obj_name to return a new object like the method in the previous sentence does?

Sorry if i'm being a fool, i've had a really bad week and my head is battered...

Cheers!