PHP Development Framework Yii Framework Tutorial (ZII) Component-menu sample

Source: Internet
Author: User

After introducing the YII database interface, introduce the ZII components from this article, including the list view ListView, the Table View GridView, and also some jquery based UI components, such as Autocomplete,datapicker, Button, Drag and drop and so on.

This article describes the menu usage, CMenu uses an HTML list to display multilevel menus, and the menu configuration is configured with its property item, which includes three primary properties

Visible is visible

Whether the active current menu item is selected,

Items submenu items.

In addition, the following properties are included:

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

Template: Optional, Menu Template

Linkoptions:array, optional, extra HTML link properties

Itemoptions:array, optional, extra HTML attribute to display menu items.

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

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

<?php 

$this->widget (' Zii.widgets.CMenu ', Array (     
        ' Items ' =>array ('
                    label ' => ' home '),
                        ' url ' =>array ('/site/index '),
                    Array (' label ' => ' about ',
                        ' url ' =>array ('/site/page ',
                        ' View ' => ')),     
                    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, the default directory for static pages is the pages subdirectory under the current Controller view directory, in this case, two static pages are created in the pages directory about.php, contact.
To use Cviewaction to display a static page, you need to modify the controller's actions method:

Public function actions ()     
{return     
    array ('     
        page ' =>array ('     
            class ' => ' Cviewaction '
            ) 
        ); 
}

In addition, if you want to show the menu's hierarchical trajectory (breadcrumbs), you can use the Cbreadcrumbs component in the Zii component, cbreadcrumbs generally with CMenu

<?php if (isset ($this->breadcrumbs)):?>
    <?php $this->widget (' Zii.widgets.CBreadcrumbs ', Array (
            ' links ' => $this->breadcrumbs,
    )); ?><!--breadcrumbs-->
<?php endif?>

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

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

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

This example downloads: Http://www.imobilebbs.com/download/yii/MenuDemo.zip

See a full set of tutorials: http://www.bianceng.cn/webkf/PHP/201301/35265.htm

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.