Welcome Guest, Not a member yet? Register   Sign In
load a Class that extends a Class ?
#1

[eluser]junkwax[/eluser]
How can I load a class that extends a class ?

I have:

application/libraries/Animal.php
application/libraries/Cat.php

Animal.php contains

Class Animal {

}

Cat.php contains

Class Cat extends Animal
{


}


I do $this->load->library( 'cat' );

but it doesnt work.

If I remove "extends Animal" it works.
#2

[eluser]pistolPete[/eluser]
There are two solutions:

1) Load both classes in this order:
Code:
$this->load->library('animal');
$this->load->library('cat');

2) Use require_once():
Code:
// must be in the same folder, otherwise change the path!
require_once('Animal.php');
Class Cat extends Animal
{
(...)
}
#3

[eluser]junkwax[/eluser]
Thank you
#4

[eluser]TheFuzzy0ne[/eluser]
I would suggest the second method, as it will only instantiate the class you're loading via the loader, and not the one it's extending. Unless of course you do want to instantiate both classes.




Theme © iAndrew 2016 - Forum software by © MyBB