Welcome Guest, Not a member yet? Register   Sign In
Using php Interfaces with CI ?
#1

[eluser]dreamynsx[/eluser]
Hi,

I would like to make use of Interfaces in CI.

How would the class loading work to make sure my base implemention class can seethe interface class.

for example, i define the following classes/files and put them under CI's libraries folder.

Code:
// AnimalInf.php
interface AnimalInf {
    var $height;
    var $weight;
}

Code:
// Dog.php
abstract class Dog {
    function bark();

}

Code:
// GermanShepard.php
class GermanShepard extends Dog implements AnimalInf {
    function bark() {
          echo "loud bark";
    }
}


I tried this but it could not see the AnimalInf class.
#2

[eluser]ejangi[/eluser]
Wouldn't you need to implement "Animal"? Not "AnimalInf"?
#3

[eluser]dreamynsx[/eluser]
Actually I would implement AnimalInf because I just changed the class name =). THanks though.

However, that is besides the original question.
#4

[eluser]ejangi[/eluser]
Sorry, I missed the important sentence in your post... Tongue

I imagine you would need to amend GermanShepard.php to include the other classes:

Code:
include(realpath(__FILE__).'/Dog.php');
include(realpath(__FILE__).'/AnimalInf.php')

class GermanShepard extends Dog implements AnimalInf {
    function bark() {
          echo "loud bark";
    }
}

And then you would just load the GermanShepard library like any other CI library.




Theme © iAndrew 2016 - Forum software by © MyBB