Home > Backend Development > PHP Tutorial > PHP development framework Yii Framework tutorial (29) Zii component-Menu example

PHP development framework Yii Framework tutorial (29) Zii component-Menu example

黄舟
Release: 2023-03-05 09:12:01
Original
1376 people have browsed it

After introducing the Yii database interface, we will introduce Zii components from this article, including ListView, GridView, and some UI components based on JQuery, such as AutoComplete, DataPicker, Button, Drag and Drop.

This article introduces the usage of Menu menu. CMenu uses Html list to display multi-level menus. Menu configuration is configured through its attribute item. Each menu item includes three main attributes

visible Whether it is visible

active Whether the current menu item is selected,

items submenu items.

In addition, it also includes the following attributes:

label: Optional, menu name, supports the use of HTML tags.

url: Optional, click on the URL link of the menu

template: optional, menu template

linkOptions: array, optional, additional HTML link attributes

itemOptions: array, optional, additional HTML for displaying menu items Attributes.

submenuOptions: array, optional, additionally displays the HTML attributes of the submenu.

Generally, the Menu can be defined 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),
),
)); ?>
Copy after login

This example uses CViewAction to display several static pages. The default directory of static pages is the pages subdirectory under the current Controller's View directory. This example creates two static pages about in the pages directory. .php, contact.
To use CViewAction to display a static page, you need to modify the Actions method of the Controller:

public function actions()
{
return array(
'page'=>array(
'class'=>'CViewAction',
)
);
}
Copy after login

In addition, if you want to display the hierarchical tracks (breadcrumbs) of the menu, you can use the CBreadcrumbs component in the Zii component , CBreadcrumbs is generally used with CMenu

breadcrumbs)):?>
widget('zii.widgets.CBreadcrumbs', array(
'links'=>$this->breadcrumbs,
)); ?>
Copy after login

This example uses Yii's default CSS, and the display result is as follows:

PHP development framework Yii Framework tutorial (29) Zii component-Menu example

If CSS is not used, the display result is as follows:

PHP development framework Yii Framework tutorial (29) Zii component-Menu example

It can be seen that you need to use the CMenu component together with appropriate CSS to display a beautiful menu.


The above is the content of the PHP development framework Yii Framework tutorial (29) Zii component-Menu example. For more related content, please pay attention to the PHP Chinese website (m.sbmmt.com) !

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template