Building Application Menus
From Delphi for PHP Documentation Wiki
Summary: This procedure describes how to build PHP application menus.
Menus provide an easy way for your users to execute logically grouped commands. You can add or delete menu items, or drag them to rearrange them during design time. The "Tool Palette" contains "MainMenu" and "PopupMenu" for building menus.
Creating menus and menu items in RadPHP XE is different than in Delphi. The menu items are specified in an array instead of being individual components with properties. Therefore, you build a menu structure using the "Items Editor" on the Items property for the MainMenu or PopupMenu components. To create application menus
- Expand the "Standard" category of the "Tool Palette" and add "MainMenu" or "PopupMenu" component to your form. A visual representation of the menu appears on the designer.
Note: A "MainMenu" component creates a menu that is attached to the title bar of the form. A "PopupMenu" component creates a menu that appears when the user right-clicks in the form.
- Click the elipsis button on the "Items" property for the menu component in the "Object Inspector".
This opens the "Items Editor" dialog box where you can define the menu items for the menu selected menu component.
- Type the text string for the menu item in the "Text" field, for example File .
- Type in a unique numeric tag ID in the "Tag" field for the menu item.
- Click the "New Item" button to add a new menu item at the same level as the selected item.To add a submenu item, click "New SubItem" and that item will be added as a child of the selected item.
To make the menu item a separator bar, place the cursor on the menu where you want a separator to appear and enter a hyphen ( - ) in the "Text" field.
Note: To build the menu structure in the "Items Editor", you need to add the items sequentially at each level. You cannot insert a menu item, nor move an item up or down in the list. To change insert items or change the structure, delete the necessary items to go back to the desired location.
- Click "OK" when you are finished building the menu structure.
To display images beside menu items
- Add the image files to your project folder on your computer.
- Expand the "Advanced" category on the "Tool Palette", select the "ImageList" component and drop it onto the form.
- Select the "Images" property in the "Object Inspector" and click its ellipsis button.
This opens the "ImageList Editor" where you list the required image files and assign them an identifier.
- Type in a unique numeric identifier for the first image in the "Key/ID column.
- Type the name of the image file in the "Filename" column.
Note: You can also click the "Load" button and browse to the image file. When you select the file this way, the name of the file is inserted in the "Filename" column. The dialog box displays the image in the box on the right.
- Click the "Add" button to create a new row and add another image.
- Add the rest of the menu images, then "OK".
- Select the menu component on the form again and open the "Items Editor" for the "Items" property.
- Type the corresponding image type="dialogNode">
Key/ID " number in the" Image Index" field for each menu item, then click "OK"..
Now the menu items will be preceded by an image at runtime. To create an event handler for a menu item
- Select the "MainMenu" or "PopupMenu" component on the form.
- Do one of the following:
- Double–click the event on the "Events" tab in the "Object Inspector" if you are creating a server event.
- Double–click the event on the "Javascript" tab if you are creating a client event.
This generates the skeleton code for the event in the source code. For example, if you were to double-click an "OnClick" event, the generated code would be the following:
function MainMenu1Click($sender, $params) { }
The IDE switches to the "Code Editor" with the mouse cursor inside the event brackets, ready to start coding the event handler.
- Type an "if" statement inside the event handler to specify which action to perform on each menu item in the menu.
| Note: |
Since the menu items are an array in the "MainMenu" or "PopupMenu" component, they do not appear as individual components in the designer with properties and events. Therefore, you must specify the events for them in "if" statements in the "MainMenu" or "PopupMenu" function. |
For example,
class Unit11 extends Page { public $ImageList1=null; public $MainMenu1=null; function MainMenu1Click($sender, $params) { if ($params['tag']==10) { //Call here your function performOpen(); } if ($params['tag']==20) { //Call here your function performSave(); } } }
To work with a pop up menu selection in javascript
function PopupMenu1JSClick($sender, $params)
{
?>
alert(event.tag);
return false;
<?php
}
[edit] See also
Creating a Database Application | Creating an InterBase PHP Database Application | Dragging an Item from the Data Explorer



