Česky
Kamil Dudka

QuickMenu - Tutorial

1. Download QuickMenu

Use next link to download necessary files:

2. Try QuickMenu yourself

There is only one thing you need to do - copy directory QuickMenu-with-example from the archive anywhere to your web server. You can compare your result with the expected one:

3. Discover example's internals

In the example package are several files. You can browse them:

Whole example code is inside index.php. Let's walk trough this file. All components on this web use config.php to load configuration. This file automatically includes file base.php with base set of classes. Class LangSelect takes care of page language switching:

require_once('config.php');
LangSelect::singleton()->handleLangSelect();

Class ClassFactory is used to import QuickMenu class definition. Instance of QuickMenu is then created. Constructor of QuickMenu does not need any parameters:

ClassFactory::importClass('QuickMenu');
$qm = new QuickMenu;

It is safe to comment next two lines - they are optional. You can use these methods to change QuickMenu behavior:

$qm->setMinimalInputLength(1);
$qm->setVisibleDepth(2);

Following code generates head part of QuickMenu output. Class JSOnloadList is used to improve interoperability with Javascript of other components used on page:

$qm->genHead();
JSOnloadList::instance()->generate();

Now you can add menu items to QuickMenu. There are two ways to add items:

  1. loadXmlTemplate method of QuickMenu class - to use XML template
  2. addItem method of QuickMenu class - to add item manually

You can use any combination of these methods.

$qm->loadXmlTemplate('QmTemplate.xml');

Sample XML template is inside example package. You can use it as base of your own templates. It contains link to DTD, so you can validate your template using W3C Markup Validation Service. The easiest way to do so:

  1. Open your XML template in Opera - it is safe to use file:// protocol.
  2. Right click on page
  3. Hit Validate item of context menu.

Once you have added items to QuickMenu, you can generate output code. Optionally you can set active item of menu using setActiveItemHREF method of QuickMenu class:

$qm->setActiveItemHREF('index.php?item='.@$_GET['item']);
$qm->genMenu();

And that's it!

Next step - config.php

Sample config.php is inside example package. You can modify this file to make this component working with other components on your web. The reference for configuration options you can find in Config class documentation. You can also download config.php from Dudka.cz web's sources.

Language switching

Try append ?lang=cz or ?lang=en to URL address of example - it should change page language. Once you change page language, it should be hold to end of session. For detail information, go to LangSelect documentation.