Welcome Guest, Not a member yet? Register   Sign In
Library class
#1

[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
#2

[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.
#3

[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 Smile

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();
#4

[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();
in my model which instantiates the class, but it caused the same error message, so then I tried printing an message in the constructor upon instancing and it worked but subsequent method calls thereafter simply would not work.

I will post the actual code I have written (its not very much) later on. I think its odd, that its not working.
#5

[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
File names must be capitalized. For example: Myclass.php

[quote author="jdav3579" date="1261028059"]
The class is defined as:
class restc{
[/quote]

Quote:From the user guide
Class declarations must be capitalized. For example: class Myclass


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.




Theme © iAndrew 2016 - Forum software by © MyBB