As you may have guessed, the core method of the class is "fetchTitles()," which is responsible for recursively navigating the "forum" database table and displaying the respective tree of nested threads. First, the method begins displaying all the main threads (the values for parent_id fields are equal to 0), and then goes as deep as required, in order to display the corresponding sub threads. You can learn how this is performed if you take a look at the signature of this method: function fetchTitles(){ In this method, you can clearly appreciate the role played by the aggregated $this->db object, which is handy when it comes to fetching all the thread titles from the database table. Undoubtedly, the most important thing to note here is the recursive implementation of the method, something extremely powerful and elegant for scanning the tree's branch nodes, in order to display all the sub threads. The remaining methods speak for themselves, so I won't spend much time on them. First, the "fetchMessages()" method is called when a thread title is clicked, and not surprisingly shows the contents of that particular thread. Its source code is listed below: function fetchMessages(){ Finally, the "createThreadForm()" method is tasked with generating, on the fly, the online form that inserts new posts on the forum. Its definition is as follows: function createThreadForm(){ In this case, the above method displays a basic web form, which after submitting itself, inserts a new message into the forum by the "addThread()" method. The source code for this one is listed below: function addThread(){ Okay, I think that's all you need to learn about how the "ThreadProcessor" class works. Now, jump into the next section, in order to see the forum in action. It's really worthwhile.
blog comments powered by Disqus |