PHP Development Framework Yii Framework Tutorial (zii) Component-menu Example

Source: Internet
Author: User
Tags yii
After introducing the Yii database interface, we introduce the Zii component from this chapter, including the List view ListView, the Tabular view of the GridView, and also include some jquery-based UI components such as Autocomplete,datapicker, Button, Drag and drop and so on.

This article describes the menu menu usage, CMenu uses an HTML list to display a multilevel menu, and the menu configuration is configured with its properties item, each of which includes three main attributes

Visible or invisible

Whether the active current menu item is selected,

Items Sub-menu items.

Also includes the following properties:

URL: Optional, click the menu to go to the URL link

Template: Optional, menu templates

Linkoptions:array, optional, additional HTML link properties

Itemoptions:array, optional, additional HTML attributes for displaying menu items.

Submenuoptions:array, optional, additional display of the submenu's HTML properties.

You can generally define menu in layout layouts, such as this example, to modify protected/views/layout/main.php

$this->widget (' Zii.widgets.CMenu ', Array (' Items ' =>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),);?>

This example uses Cviewaction to display several static pages, and the default directory for the static page is the pages subdirectory of the current controller's view directory, which in this case creates two static page about.php in the pages directory.
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 menu's hierarchical trajectory (breadcrumbs), you can use the Cbreadcrumbs component in the Zii component, Cbreadcrumbs general mates CMenu Use

breadcrumbs)): >widget (' Zii.widgets.CBreadcrumbs ', Array (' links ' = $this->breadcrumbs,));?>

This example uses the Yii default CSS to display the results as follows:

If you do not use CSS, the results are as follows:

This shows that you need to use the CMenu component together with the appropriate CSS to display beautiful menus.


The above is the PHP Development Framework Yii Framework Tutorial (ZII) component-menu sample content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • 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.