search
Homephp教程php手册Yii Framework 开发教程Zii组件-Menu 示例

Yii Framework 开发教程Zii组件-Menu 示例

Jun 13, 2016 am 10:54 AM
frameworkyiiintroduceopendevelopTutorialdatabaseExamplecomponents

 介绍完Yii数据库接口外,从本篇开始介绍Zii组件,包括列表视图ListView,表格视图GridView,此外还包括一些基于JQuery的UI组件,如AutoComplete,DataPicker, Button, Drag 和 Drop等。

 

本文介绍Menu菜单用法,CMenu使用Html 列表显示多级菜单,Menu配置通过其属性item来配置,每个菜单项包括三个主要属性

 

visible  是否可见

active 当前菜单项是否选中,

items 子菜单项。

此外还包括如下属性:

 

label: 可选,菜单名称,支持使用HTML标记.

url: 可选,点击该菜单转的URL链接

template: 可选,菜单模板www.2cto.com

linkOptions: array, 可选,额外的HTML链接属性

itemOptions: array, 可选,额外的显示菜单项的HTML属性。

submenuOptions: array, 可选,额外显示子菜单的HTML属性.

一般可以把Menu定义在Layout布局中,比如本例,修改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),

),

)); ?>

 

本例使用CViewAction来显示几个静态页面,静态页面的缺省目录为当前Controller的View目录下的pages子目录,本例在pages目录下创建了两个静态页面about.php, contact.

要使用CViewAction来显示静态页面,需要修改Controller的actions方法:

 

 

 

public function actions()

{

return array(

'page'=>array(

'class'=>'CViewAction',

)

);

}

 

此外如果要显示菜单的层次轨迹(breadcrumbs),可以使用Zii组件中的CBreadcrumbs组件,CBreadcrumbs一般配合CMenu使用

 

 

 

breadcrumbs)):?>

widget('zii.widgets.CBreadcrumbs', array(

'links'=>$this->breadcrumbs,

)); ?>

 

 

 

本例使用Yii缺省的CSS,显示结果如下:

 

 

如果不使用CSS,显示结果如下:

 

 

 

 

由此可见,需要同时使用CMenu组件配合合适的CSS才能显示漂亮的菜单。

 

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.