![]() |
Library class - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Library class (/showthread.php?tid=25570) |
Library class - El Forum - 12-16-2009 [eluser]jdav3579[/eluser] Hi, I have a class called restc.php in my application/libraries folder. The class is defined as: class restc{ var $host; function restc(){ print "in cons"; } function browse(){ print "in browse"; } } in my content model, i load it $this->load->library('restc'); $this->host="test"; When the class is initialized I get the message 'in cons', but when I call browse(), I get a fatal message, saying call to undefined stdClass::browse() in blah/models/content.php The variable is still accessible, but the methods of the class are not available. any clues? Cheers John Library class - El Forum - 12-16-2009 [eluser]jedd[/eluser] Did you not agree with the Naming Conventions described in the [url="/user_guide/general/creating_libraries.html"]Libraries[/url] section of the user guide? Oh, and with 27 posts to your name, you should probably have the hang of [ code ] tags by now. Library class - El Forum - 12-16-2009 [eluser]stuffradio[/eluser] [quote author="jedd" date="1261028630"]Oh, and with 27 posts to your name, you should probably have the hang of [ code ] tags by now.[/quote] Now now, don't be mean ![]() However, jedd is right about the naming conventions. Also, in order to access the "host" variable, you go Code: $this->Yourlibrary->host = "blah"; To call the methods in the library class, go Code: $this->Yourlibrary->method(); Library class - El Forum - 12-17-2009 [eluser]jdav3579[/eluser] Hi thanks for your swift replies. Jedd - If you mean capitalizing the first letter of the class name, then I did do that to start off with, but as I am using a Windows operating System, I thought I would try an experiment with the capitalization, but unfortunately this had no effect whatsoever, So I renamed it back. I guess your probably right about code tags, but I just forgot! :-) My 27 posts are all questions as I am such a noob at CI, unlike your goodself! :-) stuffradio - thanks, it was getting quite late(early in the morning sorry!), when I wrote the post! I originally did use: Code: $this->Restc->browse(); I will post the actual code I have written (its not very much) later on. I think its odd, that its not working. Library class - El Forum - 12-17-2009 [eluser]jedd[/eluser] I actually meant: [quote author="jdav3579" date="1261028059"] I have a class called restc.php in my application/libraries folder. [/quote] Quote:From the user guide [quote author="jdav3579" date="1261028059"] The class is defined as: class restc{ [/quote] Quote:From the user guide You're welcome to conduct experiments, for whatever purpose you want, but if you strike problems the best thing you can do is to revert things to how the guide says you should do them. If the problem goes away, you've learned something. If it doesn't, then it's interesting. |