定制 skylineos/yii-menu 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

skylineos/yii-menu

Composer 安装命令:

composer require skylineos/yii-menu

包简介

Yii2 extention for creating and managing menus

README 文档

README

Installation

Composer:

"skylineos/yii-menu": "~1.0"

Run Migrations:

php yii migrate/up --migrationPath=vendor/skylineos/yii-menu/src/migrations

It is recommended though in no way required you create a migration in your own app to link the properties createdBy and modifiedBy as foreign keys to the primary keys of your User model (whatever that may be).

Once configured (below), you should be able to access the manager at /menu/menu/index

Configuration

config/web.php

'modules' => [
    'menu' => [
        'class' => 'skylineos\yii\menu\Module',
        'viewPath' => '@app/path/to/my/admin/views', // eg. @app/modules/cms/views. The system looks for [menu|menu-item] folders
        'roles' => ['@'], // optional yii authorization roles
        'dropdownClass' => 'app\path\to\dropDownClass', // @see https://www.yiiframework.com/extension/yiisoft/yii2-bootstrap4/doc/api/2.0/yii-bootstrap4-dropdown

        /**
         * Additional templates can be added as such: (namespace => display/friendly name)
         * @see [Building Templates]
         */
        'templates' => [
            'skylineos\yii\menu\widgets\SkyMenuWidget' => 'Useful for simple demo',
            'app\widgets\menus\OtherMenuWidget' => 'My Other Custom Widget',
        ],
        
        'targets' => [
            // See 'Defining Targets'
        ]
    ],
],

Defining Link Targets

Targets (defining what the menu items can link to) can be handled three ways, all within the 'targets' property of the module:

'targets' => [
    // Here, slug will be mapped to title, both pulled directly from Content
    'app\models\Content' => [
        'slug' => 'slug',
        'display' => 'title',
        'where' => [], // optional
        'orderBy' => 'title ASC', // optional
        'dropdownGroup' => 'Pages',
    ],

    // This will interpret the model property of Router and map the 'slug' to the 'model.title' based on the fk
    // literal => false
    'app\models\Router' => [
        'slug' => 'slug',
        'display' => [
            'literal' => false,
            'className' => 'model',
            'pk' => 'id', // The primary key on the foreign model. If not provided, 'id' will be assumed
            'fk' => 'modelId',
            'property' => 'title',
            'where' => [], // optional
            'orderBy' => 'title ASC' // optional
        ],
        'where' => [],
        'orderBy' => 'title ASC',
        'dropdownGroup' => 'All Routes',
    ],

    // This will load the literal map of ProductCatalog.slug to Product.metaTitle.
    // literal => true
    'app\models\ProductCatalog' => [
        'slug' => 'slug',
        'display' => [
            'literal' => true,
            'className' => 'app\models\Product',
            'pk' => 'id', // The primary key on the foreign model. If not provided, 'id' will be assumed
            'fk' => 'modelId',
            'property' => 'metaTitle',
        ],
        'where' => [],
        'orderBy' => 'Product.sortOrder ASC',
        'dropdownGroup' => 'Products',
    ],
],

Usage

This package comes with a helper widget that will process your menu and render it using whatever templates you've configured on your menu items.

Make sure your templates (menuTemplates and dropDownTemplates) meet the requirements. See Building Templates

If these requirements do not suit your needs, you are, of course, more than welcome to develop your own widget that renders the items however you like.

<?= \skylineos\yii\menu\widgets\SkyMenuWidget::widget(['menuId' => $menuId]) ?>

Where $menuId is the id of the Menu you wish to render.

Building Templates

Menu Templates:

See examples/MenuTemplate.php in this repository

DropDown Templates:

See examples/DropDownTemplate.php in this repository

统计信息

  • 总下载量: 91
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 4
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2021-08-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固