CI2 - Is there an issue with loading libs? |
[eluser]stormbytes[/eluser]
Just upgraded to CI2 - latest build. Well.. Made the required changes to model name conventions, etc. So far looks just fine. Here's a caveat - It doesn't want to load my own libs. I created a class called MY_common.php (code below). I'm trying to load it via $this->load->library('common'); and it won't take it. I also tried autoload, same deal. Uhm.. Clues? filename: MY_common.php Code: <?php Code: An Error Was Encountered
[eluser]techgnome[/eluser]
That's a controller... not a library. You extend the controller class for controllers... for Libraries, there's nothing to extend. To define the library, you just define the class: [code] class Common {/code] Since you aren't extending anything, there's no need for the constructor (well, there might be, depending what you want to do - but there's no need for the parent::__construct call... there's no parent). -tg
[eluser]stormbytes[/eluser]
Man... The whole point of this was so that I could call: Code: $this->config->item('doc_title') This was just so I could use config values! I got the suggestion from another CI'er - Seems to have worked for him!? Oddly... Have a look: http://ellislab.com/forums/viewthread/171229/
[eluser]stormbytes[/eluser]
I tried removing the parent::Controller / extends Controller & there's no change. Here's my code: MY_common.php (application/libraries) Code: <?php if (! defined('BASEPATH')) exit('No direct script access'); Then, in my controller I'm trying to load MY_common with this call: Code: $this->load->library('common'); No change - Still get: Code: An Error Was Encountered
[eluser]boldyellow[/eluser]
Can you just use the MY_Controller? Or try cap the C: MY_Common
[eluser]stormbytes[/eluser]
Tried both - Okay this is super weird. I give up. Would've been nice to be able to use it the way you have it. Life would've been a little simpler. Oh well... Maybe it's a Ci2 issue? I dunno. I posted the problem to the other thread.. Lets see what someone comes up with. Thanks for the effort man!
[eluser]boldyellow[/eluser]
Maybe I'm unclear or since I know nothing of CI2, but I don't think you have to call it like a library. I originally got my info here: http://ellislab.com/forums/viewthread/141022/#693859 http://ellislab.com/forums/viewthread/146393/#715530
[eluser]InsiteFX[/eluser]
MY_ is for extending CodeIgniter core classes not for normal libraries Try MY_Controller and place it into application/core Change your name for MY_Common to just something else without the MY_ if it is a general library. InsiteFX
[eluser]stormbytes[/eluser]
Are Ci2 docs incomplete? I looked through the relevant sections and found no mention of any of this.
[eluser]stormbytes[/eluser]
Okay well, to keep things simpler I reverted to 1.7.2. Seems despite its stability, v.2.0 has not yet been released and as such support is very scant. Also I'm not altogether sure about how complete the docs are. I'm gonna hold off. |
Welcome Guest, Not a member yet? Register Sign In |