Welcome Guest, Not a member yet? Register   Sign In
Developing Codeigniter Libraries with proper Codeigniter / OOP fundamentals
#1

[eluser]TheresonAntaltego[/eluser]
Greetings!

I must thank CI, its amazing documentation, and the video tutorials for helping me complete a jump to more OO thinking. Most OOP examples and tutorials fail to connect with me in a sensical way. I saw how CI relates URI segments to PHP objects and their methods, and OOP clicked for me. Now I get it. I realize PHP 4 and CI may not present the whole picture of OOP programming fundamentals, but I've come a long way. And, beyond the basic hello world introduction, I've jumped right into developing a few codeigniter libraries.

So, I am a little confused as to how to get libraries to talk to each other. Say I have three libraries, one each for XML parsing, making CURL requests, and interfacing to some external API. If the proper way to load each library in CI is as follows:

Code:
... controller ..

... constructor() {

parent::constructor();
$this->load->library('the_xml_library');
$this->load->library('the_curl_library');
$this->load->library('the_external_API_library');
}

I can only see two ways for each to reference each other. The first, would be to use get_instance within the library with dependencies (the external API), and reference the required library by name in the CI super object. In this case, if I wanted to drop in a replacement library for either XML or CURL handling, I'd have to tamper with the API library. That doesn't seem right with the concept of agnostic modularity in program design. eh?

The second, would be to either pass in a reference to an instantiated dependency upon instantiation of the dependant library, or have methods within the libraries used to set references to each other. This also seems a little goofy to me.

Theoretically, each of these libraries should be PHP classes which should (or could) function without CI at all, and/or dropped in and replaced at will if they _are_ operating within CI.

I am missing something. And its either an understanding of how to develop a library for CI, or an understanding of simple OOP principles that would make my libraries pluggable. Class? Bueller?

Thank you so much for your expert tutelage.


Messages In This Thread
Developing Codeigniter Libraries with proper Codeigniter / OOP fundamentals - by El Forum - 07-06-2008, 06:04 PM



Theme © iAndrew 2016 - Forum software by © MyBB