Can someone explain $this<

windows

Guest
Ok, I am working on some code for a new (well, not so new anymore) forum I installed on my site. I wasn't quite sure how to do it, so I figured I would find the code that they already have written that kind of does what I need, but I don't totally understand it. So, I turn to the greatness which is htmlforums.

Ok, first code, than question..


/**
* Check if the forum exists. We also cause an error if
* $exists['forum_parent'] is 0 because categories can't be viewed as forums.
*/
$exists = $this->db->fetch("SELECT forum_parent, forum_name FROM {$this->pre}forums WHERE forum_id=$f");
if (!isset($exists['forum_parent']) || !$exists['forum_parent']) {
return $this->message($this->lang->forum_forum, $this->lang->forum_noexist);
}

$this->set_title($exists['forum_name']);

$topic = $this->db->fetch("SELECT COUNT(topic_id) AS count FROM {$this->pre}topics WHERE topic_forum=$f");

$pagelinks = $this->get_pages($topic['count'], 'a=forum&f=' . $f, $min, $n);
$SubForums = $this->getSubs($f);
$forumjump = $this->select_forums($this->forum_grab(), $f, 0, null, true);
$topics = $this->getTopics($f, $min, $n);

if (!$topics) {
$topics = eval($this->template('FORUM_NO_TOPICS'));
}


Alrighty, in the above code they have:

$topics = $this->getTopics($f, $min, $n);

But they have $this used over and over and over. How can they keep using that? I just don't get it at all. Vy = confused.

Is $this not a variable, or is whatever $this is, the same, how would I know that? Am I asking too many questions (ie am I in over my head?)?

Thanks guys :D ...if you can't/don't want to answer all my questions, that's ok :)They seem to be using a class of some sort.

I'm not really sure how to explain it really, but it's program Object Orientedly.

$this just says it's in this class.oh yeah *remembers* Scoutt told me that a bit ago when I first started asking. I'm kinda scatterbrained.

Ok, darn...so um...do you with with classes kinda the same as normal. I just want to do something simple. Sorry my questions aren't more specific, but I've never seen nor used a class in php :(I'm kidna confused at what you want to do?

To actually use this code, you would have to include the file with the class on it to the page you want to use it on, or do it on the same page.

what you would do is this

$class =& new classname($param1, $param2);

to instantiate the class

and then to use the functions inside the class, otherwise known as methods, you would do this

$class->method($param1, $param2);

That allows you to use the functions(methods) in the class.

That probably confused you moreoh yeah, i never told you guys what I actually wanted to do.

See, I want to make a function or something that lists the latest posts from all forums (I think that code lists the posts from one forum).

I figured I could modify the code a wee bit to accomplish what I want to do and that would be the easy. lol, I was obviously mistakenOriginally posted by Low_Overhead
Ok, I am working on some code for a new (well, not so new anymore) forum I installed on my site. I wasn't quite sure how to do it, so I figured I would find the code that they already have written that kind of does what I need, but I don't totally understand it. So, I turn to the greatness which is htmlforums.

Ok, first code, than question..


/**
* Check if the forum exists. We also cause an error if
* $exists['forum_parent'] is 0 because categories can't be viewed as forums.
*/
$exists = $this->db->fetch("SELECT forum_parent, forum_name FROM {$this->pre}forums WHERE forum_id=$f");
if (!isset($exists['forum_parent']) || !$exists['forum_parent']) {
return $this->message($this->lang->forum_forum, $this->lang->forum_noexist);
}

$this->set_title($exists['forum_name']);

$topic = $this->db->fetch("SELECT COUNT(topic_id) AS count FROM {$this->pre}topics WHERE topic_forum=$f");

$pagelinks = $this->get_pages($topic['count'], 'a=forum&f=' . $f, $min, $n);
$SubForums = $this->getSubs($f);
$forumjump = $this->select_forums($this->forum_grab(), $f, 0, null, true);
$topics = $this->getTopics($f, $min, $n);

if (!$topics) {
$topics = eval($this->template('FORUM_NO_TOPICS'));
}


Alrighty, in the above code they have:

$topics = $this->getTopics($f, $min, $n);

But they have $this used over and over and over. How can they keep using that? I just don't get it at all. Vy = confused.

Is $this not a variable, or is whatever $this is, the same, how would I know that? Am I asking too many questions (ie am I in over my head?)?

Thanks guys :D ...if you can't/don't want to answer all my questions, that's ok :)

I'll help you on msn cause I don't have time to check back for posts here...but to answer your questions:
$this is a pointer to the current instance of the current class,you use it to call/set instance variables($this->var) or methods($this->func())....meaning the code you quoted is from inside of a class....meaning in order to help you...I need to see the class.

send me the files on msn.
 
Back
Top