承接 execut/yii2-base 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

execut/yii2-base

最新稳定版本:1.14.2

Composer 安装命令:

composer require execut/yii2-base

包简介

My base classes for yii2

关键字:

README 文档

README

My base classes for yii2

Bootstrap system

execut\yii\Bootstrap

Этот класс необходим для возможности иерархического запуска компонентов для различных модулей. Допустим есть модуль users, для своей работы он требует навигацию execut/yii2-navigation и модуль CRUD execut/yii2-crud. Их необходимо запустить до запуска основного модуля users. При этом самим этим компонентам нужно запускать ещё комоненты для своей работы. Например, execut/yii2-crud требует пакет execut/yii2-actions. С помощью execut\yii\Bootstrap компоненты рекурсивно сами подцепят себе всё необходимое и не нужно об этом заботиться. Нам-же нужно запустить модуль users и указать от запуска каких компонентов он зависит. Для этого необходимо реализовать потомка класса \execut\yii\Bootstrap, объявив в нём все зависимости модуля users и саму настройку модуля users:

<?php
namespace execut\users;


class Bootstrap extends \execut\yii\Bootstrap
{
    public function getDefaultDepends()
    {
        return [
            'bootstrap' => [
                'yii2-navigation' => [
                    'class' => \execut\navigation\Bootstrap::class,
                ],
                'yii2-crud' => [
                    'class' => \execut\crud\Bootstrap::class,
                ],
            ],
            'modules' => [
                'users' => [
                    'class' => Module::class,
                ],
            ],
        ];
    }
    
    public function bootstrap($app)
    {
        parent::bootstrap($app); // Здесь можно задать код для бутстрапа модуля. Родителя вызвать обязательно
    }
}

После этого добавляем в конфигурацию приложения запуск модуля users. Прелесть бутрапа в том, что сам модуль как и все необходимые компоненты указывать в конфигурации приложения не нужно, поскольку это всё и так объявлено в бутстрапе:

...
'bootstrap' => [
    'users' => [
        'class' => \execut\users\Bootsrap::class,
    ],
],
...

Если ещё необходимо задать модулю параметры окружения приложения, то указываем их через директиву depends в конфиге:

...
'bootstrap' => [
    'users' => [
        'class' => \execut\users\Bootsrap::class,
        'depends' => [
            'modules' => [
                'users' => [
                    'defaultRoute' => '/users'
                ],
            ],
        ],
    ],
],
...

Widgets system

execut\yii\jui\Widget

This class provides the ability to simplify create jquery widgets with assets files if you want. To create a widget, you must create files in follow structure:

  • CustomWidget.php
  • CustomWidgetAsset.php
  • assets\CustomWidget.js
  • assets\CustomWidget.css
  1. CustomWidget.php

Create class for you widget:

class CustomWidget extends \execut\yii\jui\Widget
{
    public function run()
    {
        /**
         * If you want append assets files and create javascript widget instance
         */
        $this->registerWidget();
        
        /**
         * Or if you want only append assets files
         */
        $this->_registerBundle();

        /**
         * renderContainer - helper method for wrapping widget in div container with defined in widget options
         */
        $result = $this->renderContainer($this->renderWidget());

        return $result;
    }
    
    protected function renderWidget() {
        /**
         * Here generate widget out $result
         */
         
         return $result;
    }
}
  1. CustomWidgetAsset.php

Define asset bundle class in same folder and name with postfix Asset

class CustomWidgetAsset extends \execut\yii\web\AssetBundle
{
}
  1. assets\CustomWidget.js

If you want javascript functional, create jquery widget file assets\CustomWidget.js:

(function () {
    $.widget("customNamespace.CustomWidget", {
        _create: function () {
            var t = this;
            t._initElements();
            t._initEvents();
        },
        _initElements: function () {
            var t = this,
                el = t.element,
                opts = t.options;
        },
        _initEvents: function () {
            var t = this,
                el = t.element,
                opts = t.options;
        }
    });
}());
  1. assets\CustomWidget.css

If you want css styles, create file assets\CustomWidget.css:

.custom-widget {
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2015-11-23