Chapter 3 - adding pages to the administration center

Now that pluck knows everything it has to know about our new module, we can start implementing our own pages in the administration center. First thing we need to do, is implement a start page.

Adding a start page

The start page of a module is the page that shows up after the user has clicked on your module in the administration center. So, if a module has a start page, this page will be linked to on the module page from the main menu.

Pluck inserts pages by including PHP-files. So, we created a PHP-file called start.php which contains the start page of our module. This file can contain of course any PHP-code you want. It's not needed to include html-start tags or things like that, pluck does that for you. It also doesn't matter what filename the file has; you'll see that later on in this chapter.

Ok, so now we have our start-page ready, we need to know how to include it in the administration center. Now we need to create another directory, called pages_admin. We'll create this directory inside our module-dir, so for our poll module it'll be data/modules/polls/pages_admin/. Pluck will search in this directory for files to include in the administration center. We want to include start.php in the administration center, so we put that file inside the directory (we then have data/modules/polls/pages_admin/start.php).

Ok, well done! Now we can tell pluck that it has to include start.php as the start page of our module. Therefore, we need to make a file called module_pages_admin.php in our module directory. So in our case, we create the file data/modules/polls/module_pages_admin.php.

Then we can use the variable $startpage to define the filename of our start page. So in our case, this will be the content of data/modules/polls/module_pages_admin.php:

<?php
$startpage = "albums.php";
?>

If you now click on modules in the main menu of plucks administration center, you can see your module listed! The title of the module will be a link to it's start page.

It's possible that your module doesn't need any pages implemented in the administration center (just like the contact form module). That's possible; just don't create a module_pages_admin.php file for your module.

Adding more pages

Well, congratulations! You just included your first module page! But, most modules of course contain more than one page: our poll module for example, also needs a page for adding a new poll. How can we do that?

Adding the page

We already have a PHP-file that contains the code for the "new poll"-page we want to implement. This file is for example called new_poll.php, and we put it in our pages_admin directory.

Now, we need pluck to tell the file is there. You can use the following code to do this:

$module_page['filename_without_extension'] = "title of the page";
  • filename_without_extension just is the filename of the page we want to implement (in our case new_poll.php), but without the extension. In our case, we need to fill in new_poll here.
  • You can replace title of the page with the title of the page you want to implement. Pluck will show this title on the top of the page.

In our case, we'll put the following code in module_pages_admin.php:

$module_page['new_poll'] = "create a new poll";

Linking to the page

We know have inserted the page, but we don't know yet how we can access it. This is important to know, because we want to place a link to the "new poll"-page inside the start page of the module.

The URL of a module-page in the administration center will always look like this:

admin.php?module=module_dir&page=filename_without_extension
  • module_dir is the same as the name of your module-dir, and also the same as the $module_dir variable inside module_info.php (for more information, see Chapter 2). In our case, this is polls.
  • filename_without_extension is the same filename without extension you put in module_pages_admin.php. In our case, this is new_poll.

So, the entire URL to access our "new poll"-page is:

admin.php?module=polls&page=new_poll

We can link to the page like this:

<a href="admin.php?module=polls&page=new_poll">create a new poll</a>

The URL to the start page of a module will always look like this:

admin.php?module=module_dir

So, in our case, it'll be:

admin.php?module=polls

Resulting code

If we also implement some other pages, this could be an example of the resulting code in module_pages_admin.php:

<?php
$startpage = "albums.php";
$module_page['new_poll'] = "create a new poll";
$module_page['del_poll'] = "delete poll";
$module_page['edit_poll'] = "edit a poll";
?>

Ok, let's go to the next chapter!

Let's go to the next chapter and learn how to add pages to the website! Go to the next chapter...

 
dev/modules/chapter_3.txt · Last modified: 2008/08/04 11:34 (external edit)
 
Recent changes RSS feed Creative Commons License Driven by DokuWiki