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

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

Jun 13, 2016 am 10:54 AM
framework yii introduce open develop Tutorial database Example components

 介绍完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 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

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

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

In summer, you must try shooting a rainbow In summer, you must try shooting a rainbow Jul 21, 2024 pm 05:16 PM

After rain in summer, you can often see a beautiful and magical special weather scene - rainbow. This is also a rare scene that can be encountered in photography, and it is very photogenic. There are several conditions for a rainbow to appear: first, there are enough water droplets in the air, and second, the sun shines at a low angle. Therefore, it is easiest to see a rainbow in the afternoon after the rain has cleared up. However, the formation of a rainbow is greatly affected by weather, light and other conditions, so it generally only lasts for a short period of time, and the best viewing and shooting time is even shorter. So when you encounter a rainbow, how can you properly record it and photograph it with quality? 1. Look for rainbows. In addition to the conditions mentioned above, rainbows usually appear in the direction of sunlight, that is, if the sun shines from west to east, rainbows are more likely to appear in the east.

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

How to handle database connection errors in PHP How to handle database connection errors in PHP Jun 05, 2024 pm 02:16 PM

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

Detailed introduction of Samsung S24ai functions Detailed introduction of Samsung S24ai functions Jun 24, 2024 am 11:18 AM

2024 is the first year of AI mobile phones. More and more mobile phones integrate multiple AI functions. Empowered by AI smart technology, our mobile phones can be used more efficiently and conveniently. Recently, the Galaxy S24 series released at the beginning of the year has once again improved its generative AI experience. Let’s take a look at the detailed function introduction below. 1. Generative AI deeply empowers Samsung Galaxy S24 series, which is empowered by Galaxy AI and brings many intelligent applications. These functions are deeply integrated with Samsung One UI6.1, allowing users to have a convenient intelligent experience at any time, significantly improving the performance of mobile phones. Efficiency and convenience of use. The instant search function pioneered by the Galaxy S24 series is one of the highlights. Users only need to press and hold

How to retrieve the wrong chain of virtual currency? Tutorial on retrieving the wrong chain of virtual currency transfer How to retrieve the wrong chain of virtual currency? Tutorial on retrieving the wrong chain of virtual currency transfer Jul 16, 2024 pm 09:02 PM

The expansion of the virtual market is inseparable from the circulation of virtual currency, and naturally it is also inseparable from the issue of virtual currency transfers. A common transfer error is the address copy error, and another error is the chain selection error. The transfer of virtual currency to the wrong chain is still a thorny problem, but due to the inexperience of transfer operations, novices often transfer the wrong chain. So how to recover the wrong chain of virtual currency? The wrong link can be retrieved through a third-party platform, but it may not be successful. Next, the editor will tell you in detail to help you better take care of your virtual assets. How to retrieve the wrong chain of virtual currency? The process of retrieving virtual currency transferred to the wrong chain may be complicated and challenging, but by confirming the transfer details, contacting the exchange or wallet provider, importing the private key to a compatible wallet, and using the cross-chain bridge tool

How to connect to remote database using Golang? How to connect to remote database using Golang? Jun 01, 2024 pm 08:31 PM

Through the Go standard library database/sql package, you can connect to remote databases such as MySQL, PostgreSQL or SQLite: create a connection string containing database connection information. Use the sql.Open() function to open a database connection. Perform database operations such as SQL queries and insert operations. Use defer to close the database connection to release resources.

Why do you need to know histograms to learn photography? Why do you need to know histograms to learn photography? Jul 20, 2024 pm 09:20 PM

In daily shooting, many people encounter this situation: the photos on the camera seem to be exposed normally, but after exporting the photos, they find that their true form is far from the camera's rendering, and there is obviously an exposure problem. Affected by environmental light, screen brightness and other factors, this situation is relatively normal, but it also brings us a revelation: when looking at photos and analyzing photos, you must learn to read histograms. So, what is a histogram? Simply understood, a histogram is a display form of the brightness distribution of photo pixels: horizontally, the histogram can be roughly divided into three parts, the left side is the shadow area, the middle is the midtone area, and the right side is the highlight area; On the left is the dead black area in the shadows, while on the far right is the spilled area in the highlights. The vertical axis represents the specific distribution of pixels

See all articles