• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Load Interface?

#1
[eluser]ee99ee[/eluser]
Hi. I'm using $this->load->library() to load a class library, but how do I load an interface?

I tried:
Code:
$CI =& get_instance();
$CI->load->library('Billing/IBillingSystem');

But apparently that requires a class called IBillingSystem and not just an Interface, which is all that file has.

-Chris

#2
[eluser]smilie[/eluser]
By interface you mean function name?

From User Guide:
Naming Conventions

File names must be capitalized. For example: Myclass.php
Class declarations must be capitalized. For example: class Myclass
Class names and file names must match.

See: http://ellislab.com/codeigniter/user-gui...aries.html

So, either modify file and add class;

Or you can move file to the helpers - which do not require class.

Cheers,
Smilie

#3
[eluser]ee99ee[/eluser]
No, I mean an interface

http://php.net/manual/en/language.oop5.interfaces.php

#4
[eluser]techgnome[/eluser]
As far as I know, CI doesn't have a way to load interfaces. You can't load like a library because it isn't one. Not sure why you need an interface, but I'd think that simply using an include for the file should be sufficient.

-tg

#5
[eluser]ee99ee[/eluser]
Well, we're trying to use good design patterns.... that's too bad it doesn't support it though. But alright. Thanks!

#6
[eluser]TaylorOtwell[/eluser]
I usually setup an auto-loader to handle interfaces.

However, I just recently finished a DI framework and IoC container for CI 2.0 that I'm planning to release soon. I just need to tidy up a few things. With it, you can bind interfaces to implementations and let the IoC container resolve your dependencies for you.

And, if you want, with two lines of code in the CodeIgniter.php core file you can even let it build your controllers for you, allowing constructor injection on your controllers.

If your interested in getting your hands on it early, just let me know.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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