[Solution] Extending libraries: proper locations for the Classname and MY_Classname library files |
[eluser]aidehua[/eluser]
This is probably second nature to most of you, but I've just spent an hour trying to figure it out so I thought I'd post it here in case it might save someone else five minutes down the line. (I was using Simon Maddox's Twitter class (available at http://github.com/simonmaddox/codeigniter-twitter), but I think this would apply to any library class in CodeIgniter.) First up I downloaded the class file (Twitter.php) and saved it in my application/libraries folder. I was able to load it successfully from the controller in the usual way: Code: $this->load->library('twitter'); But then I wanted to extend the class a little bit, so I created a new class and called it MY_Twitter.php (as documented at http://ellislab.com/codeigniter/user-gui...aries.html). I saved my new class in the application/libraries folder. I then tried to load the extended library from the controller, again as per the documentation, in the normal way: Code: $this->load->library('twitter'); This returned an error: "Unable to load the requested class: Twitter" After much experimenting, I found the solution: I moved the Twitter.php file out of the application/libraries folder, and into the system/libraries folder, so that I now had: codeigniter/system/libraries/Twitter.php codeigniter/application/libraries/MY_Twitter.php It now works just fine. I wonder if the documentation might make more explicit the following point: "3rd-party" library classes should be saved in the system/libraries folder. (Extensions to 3rd-party library classes, using the MY_ prefix, should be saved in the application/libraries folder. PS This post is about library classes in general, not specifically about this Twitter class. But, for what it's worth, my new class looked like this: Code: <? |
Messages In This Thread |
[Solution] Extending libraries: proper locations for the Classname and MY_Classname library files - by El Forum - 11-04-2009, 05:51 AM
[Solution] Extending libraries: proper locations for the Classname and MY_Classname library files - by El Forum - 11-04-2009, 06:21 AM
[Solution] Extending libraries: proper locations for the Classname and MY_Classname library files - by El Forum - 11-04-2009, 06:35 AM
|