Yii Framework development tutorial Zii component-Menu example

Source: Internet
Author: User

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 item, each menu item includes three main attributes: visible, whether the current menu item is visible, and whether the current menu item is selected. The items sub-menu item. It also includes the following attributes: label: (optional) menu name. HTML tags are supported. url: Optional. Click the URL link template to go to this menu. Optional. Menu template: www.2cto. comlinkOptions: array. Optional. Additional HTML link attributes: itemOptions: array. Optional. Additional HTML attributes of menu items are displayed. SubmenuOptions: array (optional) HTML attribute of the sub-Menu. You can define the Menu in the Layout layout. For example, in this example, modify 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' => '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',);} if you want to display the menu level track (breadcrumbs ), the CBreadcrumbs component in Zii can be used. CBreadcrumbs is generally used with CMenu. <? Php if (isset ($ this-> breadcrumbs):?> <? Php $ this-> widget ('zii. widgets. CBreadcrumbs ', array ('link' => $ this-> breadcrumbs,);?> <! -- Breadcrumbs --> <? Php endif?> In this example, the default CSS of Yii is used. The result is as follows: if CSS is not used, the result is as follows: You need to use the CMenu component together with the appropriate CSS to display the beautiful menu.

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.