PHP development framework YiiFramework tutorial (29) Zii component-Menu example
In addition to the Yii database interface, this article introduces Zii components, including list view ListView and table view GridView. In addition, it includes some JQuery-based UI components, such as AutoComplete, DataPicker, Button, drag and Drop.
This article introduces Menu usage. CMenu uses Html columns to display multi-level menus. Menu configuration is configured through its attribute items. each Menu item includes three main attributes.
Visible
Whether the current menu item is selected,
Items sub-menu item.
It also includes the following attributes:
Url: Optional. click the URL link to be converted from the menu.
Template: Optional. menu template.
LinkOptions: array (optional) Additional HTML link attributes
ItemOptions: array (optional) HTML attribute of an additional menu item.
SubmenuOptions: array. optional. The HTML attributes of the sub-menu are displayed.
You can generally define the Menu in the Layout layout. for example, in this example, modify protected/views/Layout/main. php.
$ This-> widget ('zii. widgets. CMenu ', array (
'Items '=> array (
Array ('label' => 'home ',
'URL' => array ('/site/index ')),
Array ('label' => 'about ',
'URL' => array ('/site/page ',
'View' => 'about ')),
Array ('label' => 'Contact ',
'URL' => array ('/site/page ',
'View' => 'Contact ')),
Array ('label' => 'login ',
'URL' => array ('/site/login '),
'Visible '=> false ),
),
);?>
In this example, CViewAction is used to display several static pages. the default directory of the static page is the pages subdirectory under the View Directory of the current Controller. In this example, two static pages are created under the pages directory, about. php, contact.
To use CViewAction to display static pages, modify the Controller's actions method:
Public function actions ()
{
Return array (
'Page' => array (
'Class' => 'cviewaction ',
)
);
}
In addition, if you want to display the breadcrumbs, you can use the CBreadcrumbs component in Zii. CBreadcrumbs is generally used with CMenu.
Breadcrumbs):?>
Widget ('zii. widgets. CBreadcrumbs ', array (
'Link' => $ this-> breadcrumbs,
);?>
In this example, the default CSS of Yii is used. The result is as follows:
If no CSS is used, the result is as follows:
It can be seen that you need to use the CMenu component together with the appropriate CSS to display beautiful menus.