UPB2 Forum Listing
From MyUPBWiki
Notes about the required update: "Put it all together" section needs to be updatedI will assume you have already read the Hello World tutorial and so you have a basic understanding of how the upb system works. So lets go ahead and get started shall we!
Contents |
Getting Setup
For this tutorial we will go ahead and create all the files nessassary to get the module up and running.
- upb2/includes/commands/index.php
- upb2/lang/en/index.lang
- upb2/skins/myupb/tpl/index.tpl
Now you will notice an extra file, index.lang, which we did not use for the Hello World example. Since the module we are creating here is a standard UPB module we will include everything.
The order I generally follow for creating a module is to create the template first, then the command file and finally the language file. Following that lets start off by making the template...
Creating the Template
IN PROGRESS...
Creating the Command
Since the template is all set in place its easy for us to goto the command file and create all the code that makes cool things happen! Following the idea of OOP we want to break down the code into small managable blocks of code. Lets start by writing the initialization function of upbPage.
upbPage()
The goal of this module is to display a listing of all the available forums I have access to. So, thats exactly what this function should do.
function upbPage($command) {
// Initialize
$this->upb($command);
$this->tpl_loadTemplate("index.tpl");
// Grab all the forum permissions
$this->tdb_forumPerms();
// Get the categories (along with the forums in them)
if(!$this->listCategories())
$this->tpl_newBlock("no_categories", array(
"msg" => $this->lang_get(1),
"add_cat" => $this->tdb_adminpanel() ? $this->lang_get(2) : $this->lang_get(3)
));
// Finish up
$this->_upb();
}
I will just quickly explain whats going on here. We initialize the upb class with $this->upb($command) and load up the template for this command. $this->tdb_forumPerms() is a function declared in the auth class which gives us the information needed to determine which forums the user browsing has access too (we don't want to display any private forums to users without access).
This next part of code requires a little more explaination. We call $this->listCategories() which by the looks of how its used returns a boolean value. This function actually isn't defined yet, we are trying to break up the code into smaller sections as I said earlier. So, our function listCategories will return false if something went wrong and we can display our error message using $this->tpl_newBlock(). This is when the template and language classes come into play.
IN PROGRESS...
Putting it all together
IN PROGRESS...
