Quick search:

6. Custom MenuPart

This application is situated in the example6 folder. To run it on your own server you need the same data as for example3. To try it out on the phpPeanuts website click here.

It extends a copy from example 5 with a custom part: a MenuPart that highlights the option in the application submenu that matches the current Page.

In order to specialize the submenu we needed to know how from where it is generated. This is explained in how to specialize a part of a page. We have set the debug mode for example 6 to 'verbose', so you can see the debug information in source of the page. Mind that you see it while the new MenuPart class is already in use.

To create a special version of class MenuPart for the example6 application we copied the file 'classMenuPart.php' from the root classFolder to the example6 classFolder. Generally classes in the root folder do not contain any code. But you may use the classes in the root classFolder to override framework behavior for all you applications. If you do, be aware that you can not inherit code from a class in the root classFolder in a class with the same name in an application classFolder. If you need that kind of inheritance see how to keep your generic code separated from your application code.

Once we had a special MenuPart class, we could create a method to produce the lines of the submenu. We called it printSubmenuLines
. In skinSubMenu.php we replaced the menu lines with a table without rows, and a call to the printSubmenuLines method of the part object.

The individual rows are produced by the printSubmenuLine method. It uses data about the menu lines from the submenuData field. This field is initialized by the initSubmenuData method, where we hardcoded the data. We could have read if from a structured file, like XML or CSV, or retrieved it from a database just as easily. But in this example the hard coded data is OK, because the part class is specific to the application and the submenu is too.

Before printing the printSubmenuLine method checks for the pntType, pntHandler and id parameters in the requestData field (This field normally holds a copy of the data from the $_REQUEST variable). If they are equal to the ones to put in the url of the menu item, the current page must be the same as the one the menu item refers to. To highlight the menu item it then puts HTML source for setting the background color in a variable $rowHighLight. This varable is  included in the TR tag in the printed string.

User Contributed Notes

2008-07-28 05:24:04
The download contains incorrect data in the skinSubmenu.php file.

It is:-


but should be:-

2008-07-28 09:20:34
I guess you entered (left square brackett)?php $this->printSubmenuLines() (right square bracket) in your post, but it has been removed by the forum software, which does not allow tags.

It is not data, but code. PHP  should output the right data when it executes the code. See http://www.php.net/manual/en/tutorial.firstpage.php