YiiFramework development tutorial Zii component-Menu example _ PHP Tutorial

Source: Internet
Author: User
YiiFramework development tutorial 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, 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 the Html list 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 www.2cto.com

LinkOptions: array (optional) Additional HTML link attributes

ItemOptions: array (optional) HTML attribute of an additional menu item.

SubmenuOptions: array. optional. The HTML attribute of the sub-menu is displayed.

You can generally define the Menu in the Layout layout. for example, in this example, modify protected/views/Layout/main. php.

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, you need to 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 following result is displayed:

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

Success ,...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.