Quantcast
Channel: Live News for Yii Framework
Viewing all 2943 articles
Browse latest View live

[news] ApiDoc extension version 2.1.3 released

$
0
0

We are very pleased to announce the release of the ApiDoc extension version 2.1.3.

This release has two important bugfixes about @inheritdoc and getter/setter methods. Also it contains two enhancements:

  • @since tags are now propagated to inherited methods/properties in the same package.
  • HTTPS is now used for www.php.net links.

See the CHANGELOG for a full list of changes.

Thank you, Brandon Kelly and Somogyi Márton for this release pull requests.


[extension] startpl/yii2-nested-sets-menu

$
0
0

Nested Sets Menu Widget

  1. Installation
  2. Usage

Widget to display nested sets as Menu

PackagistPackagist Version

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist startpl/yii2-nested-sets-menu "*"

or add

"startpl/yii2-nested-sets-menu": "*"

to the require section of your composer.json file.

Usage

A basic usage looks like the following: `php

  • <?= Menu::widget([
  • 'items' => \startpl\yii2NestedSetsMenu\services\MenuArray::getData($data), // $data is your models|rows
  • 'options' => ['id'=>'main-menu', 'class' => 'menu'],
  • 'encodeLabels'=>false,
  • 'activateParents'=>true,
  • 'activeCssClass'=>'active',
  • ]);?>
  • `

Also you can extending of MenuArray, NestedSetsTreeMenu for fine-tune your data

[extension] letsjump/yii2-anchorjs

$
0
0

AnchorJS

  1. Overview
  2. Installation
  3. Usage
  4. Application wide configuration

Yii2 wrapper for AnchorJS that add deep anchor links to your Yii docs.

Overview

AnchorJS lets you drop deep anchor links (like these) onto any webpage, and be on your way.

You don't need to set up IDs or worry about urls. AnchorJS will respect your IDs if you have them, and generate them if you don't.

It uses an attractive link icon by default, but you can customize the display via options and CSS styling. The examples demonstrate a few customization ideas.

Finally, AnchorJS is lightweight, accessible, and dependency-free.

Example: The bootstrap manual:

bootstrap

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist letsjump/yii2-anchorjs "*"

or add

"letsjump/yii2-anchorjs": "*"

to the require section of your composer.json file.

Usage

Once the extension is installed, simply add this in any view that need it.

<?= \letsjump\AnchorJS\AnchorJS::widget([
        'add' => 'h1, h2',
        'options' => [
            'placement'=>'right', 
            'icon'=>'',
            // ... refer to https://www.bryanbraun.com/anchorjs/#options for any option available
        ], 
]); ?>

Application wide configuration

You can set an application wide configuration by adding its options to your /app/config/params.php `php <?php

return [

'adminEmail' => 'admin@example.com',
'anchorjs'   => [
    'placement' => 'left',
    'icon' => ''
    // ... refer to https://www.bryanbraun.com/anchorjs/#options for any option available
],

]; `

[extension] buttflattery/yii2-multimenu

$
0
0

Yii2-multimenu

  1. What is this repository for?
  2. External Libraries Used
  3. About Bootstrap Version Usage
  4. Demos
  5. Usage
  6. Available Options for the Widget
  7. BigDrop minimal options with brand text
  8. Leftnav Minimal options with brand image
  9. Dropup menu with custom color theme Asset Class
  10. Menu items from Database
  11. Available Constants

What is this repository for?

A Yii2 widget that creates a navigation menu based on the yii\widgets\Menu, and provides you with multiple layout options that include a Big Drop style top navigation, a Left Menu navigation and a Sticky drop-up footer menu just by using this single widget. it uses multilple 3rd party plugins for animating the menu. It provide an extra helper component to build menu from the model.

preview

External Libraries Used

About Bootstrap Version Usage

The extension detects if you are using the yiisoft/yii2-bootstrap or yiisoft/yii2-bootstrap4 and loads the appropriate assets for the extension. It will check first the "yiisoft/yii2-bootstrap4" if it exists then it will load bootstrap4 resources otherwise it will fall back to use bootstrap3. So make sure you are following the correct guide to use the yiisoft/yii2-bootstrap4" and remove the "yiisoft/yii2-bootstrap": "~2.0.0", from you composer.json and change the minimum-stability:"dev" here is the complete guide.

How do I get set up

use composer to install the extension

php composer.phar require  buttflattery/yii2-multimenu "@dev"

or add into the composer.json file under require section

"buttflattery/yii2-multimenu":"@dev"

Demos

Usage

<?php
    echo MultiMenu::widget(
        [
            'activeCssClass' => 'active',
            'items' => Yii::$app->menuhelper->getMenuItems(),
            'brandLabel' => 'Left Navigation',
            'brandImage' => 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAB+0lEQVR4AcyYg5LkUBhG+1X2PdZGaW3btm3btm3bHttWrPomd1r/2Jn/VJ02TpxcH4CQ/dsuazWgzbIdrm9dZVd4pBz4zx2igTaFHrhvjneVXNHCSqIlFEjiwMyyyOBilRgGSqLNF1jnwNQdIvAt48C3IlBmHCiLQHC2zoHDu6zG1iXn6+y62ScxY9AODO6w0pvAqf23oSE4joOfH6OxfMoRnoGUm+de8wykbFt6wZtA07QwtNOqKh3ZbS3Wzz2F+1c/QJY0UCJ/J3kXWJfv7VhxCRRV1jGw7XI+gcO7rEFFRvdYxydwcPsVsC0bQdKScngt4iUTD4Fy/8p7PoHzRu1DclwmgmiqgUXjD3oTKHbAt869qdJ7l98jNTEblPTkXMwetpvnftA0LLHb4X8kiY9Kx6Q+W7wJtG0HR7fdrtYz+x7iya0vkEtUULIzCjC21wY+W/GYXusRH5kGytWTLxgEEhePPwhKYb7EK3BQuxWwTBuUkd3X8goUn6fMHLyTT+DCsQdAEXNzSMeVPAJHdF2DmH8poCREp3uwm7HsGq9J9q69iuunX6EgrwQVObjpBt8z6rdPfvE8kiiyhsvHnomrQx6BxYUyYiNS8f75H1w4/ISepDZLoDhNJ9cdNUquhRsv+6EP9oNH7Iff2A9g8h8CLt1gH0Qf9NMQAFnO60BJFQe0AAAAAElFTkSuQmCC',
            'brandUrl' => 'https://yii2plugins.omaraslam.com',
            'activateParents' => true,
            'layoutTemplate'=>'{multimenu}{brand}',
            'enableIcons'=>true,
            'multimenuOptions' => [
                'theme' => MultiMenu::THEME_LEFTNAV,
                'mobileView' => true,
                MultiMenu::THEME_LEFTNAV => [
                    'position'=>MultiMenu::LEFT_NAV_FIXED,
                    'slimScroll' => [
                        'scrollColor' => 'rgba(0,0,0,0.75)'
                    ]
                ]
            ]
        ]
    );
?>

Available Options for the Widget

You can use the available default options for the yii\widgets\Menu along with the following options

$brandImage (string|bool)

Src of the brand image or false if it's not used. Note that this param will override $this->brandLabel param. Default value is false.

$brandLabel (string|bool)

The text of the brand or false if it's not used. Note that this is not HTML-encoded. Default value is false.

$brandOptions (array)

The HTML attributes of the brand link. \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.

$brandUrl (bool)

The URL for the brand's hyperlink tag. This parameter will be processed by [[\yii\helpers\Url::to()]] and will be used for the "href" attribute of the brand link. Default value is false that means [[\yii\web\Application::homeUrl]] will be used. You may set it to null if you want to have no link at all.

$containerCssClasses (array)

The Container HTML options.

$layoutTemplate (string)

The layout template used to draw the menu and rearrange the brand and menu items placement. Default value is {brand}{multimenu}.

$enableIcons (bool)

If default icon should be enabled along with the labels of the menu. It uses the Multmenu::DEFAULT_ICON which has the value <i class="ion-android-menu"></i>

$multimenuOptions (array)

You can pass the plugin specific settings here for the multimenu and settings depending on the type of the menu you are using.

  • theme (string)

    The theme of the menu you want to use, it can be any of the bigdrop,leftnav and dropup, you can use the available constants THEME_BIGDROP, THEME_LEFTNAV and THEME_DROPUP. See available constants section.

  • themeColorFile (string)

    The name space of the theme color file you want to load with the menu you can customize classes for the menu and load via this option. Default value is empty ''. See wiki for creating the theme file.

  • mobileView (bool)

    If enabled, the menu will be responsive in the mobile view. This option comes handy when you want to use 2 menus on the same page and want one of them to be show for the mobile view, you can turn the other one off. Default value is true.

  • enableWavesPlugin (bool)

    If the Waves. plugin should be enabled when clicking on the menu items. Default value is true.

  • wavesEffect (string)

    The color of the waves effect see https://materializecss.com/waves.html#! . Default value is waves-cyan.

  • wavesType (string) circular|default

    The waves type effect, circular or default. Default value is default. See the constants section to see all available effects you can use.

  • mobileBreakPoint (int)

    The mobile view break point where the javascript plugin should recalculate sizes. Default value is 1200. (Note: dont change this option unless you know what you are doing as changing it will require you to update the media queries for the themes too.)

There are menu/theme specific options that are applicable to specific menu types only. See details below.

  • bigdrop (array)

    It accepts the following settings to be used for bigdrop menu only.

    • enableTransitionEffects (bool) : Enable transition effects on the menu, uses animate.css. default is true.

    • transitionEffect (string) : Transition effect to show the menu. default value flipInX . See animate.css for trasition effect types.

    • transitionDelay (string) : Animate speed for the transition "fast"|"faster"|"slow"|"slower"|"". Default value faster. See available constants.

  • dropup (array)

    It accepts the the same set of settings as above for the bigdrop but uses different default values

    • enableTransitionEffects => true
    • transitionEffect => 'fadeIn`
    • transitionDelay => 'slow'
  • leftnav (array)

    It accepts the the same set of settings as above for the bigdrop with different default values, and some extra options for the leftnav.

    • enableTransitionEffects => true

    • transitionEffect => 'fadeIn`

    • transitionDelay => 'slow'

    • position (string) default|fixed|absolute : the position of the left menu, the default value is default and the leftnav will be rendered relative to it's parent container.

    • slimScroll (array) : The options for the slimscroll plugin used for the left nav.

      • scrollColor (string) : The scroll bar color, default value is rgba(0,0,0,0.8).

      • scrollWidth (string) : Width of the scroll bar, default value is 4px.

      • scrollAlwaysVisible (bool) : If true scroll will always be visible, default value is false.

      • scrollBorderRadius : The scroll bar border radius, default value is 0.

      • scrollRailBorderRadius : Sets border radius of the rail, default value is 0.

      • scrollActiveItemWhenPageLoad : If true, will always scroll to the active menu item link after the page loads, default value is true.

Remember when using any on the following menus if you are providing the items array manually, when specifying label for the submenus that further opens a menu you should not leave the url blank but javascript::void(0) as in the examples below.

BigDrop minimal options with brand text

<?php
    use buttflattery\multimenu\MultiMenu;
    $items = [
            ['label' => 'Home', 'url' => ['/site/index']],
            ['label' => 'About', 'url' => ['/site/about']],
            ['label' => 'Contact', 'url' => ['/site/contact']],
            [
                'label' => 'Dropdown',
                'url' => 'javascript:void(0)',
                'items' => [
                    ['label' => 'Level 1  Dropdown A', 'url' => '#'],
                    ['label' => 'Level 1  Dropdown B', 'url' => '#'],
                ],
            ],
            Yii::$app->user->isGuest ? (
                ['label' => 'Login', 'url' => ['/site/login']]
            ) : (
                '<li>'
                . Html::beginForm(['/site/logout'], 'post')
                . Html::submitButton(
                    'Logout (' . Yii::$app->user->identity->username . ')',
                    ['class' => 'btn btn-link logout']
                )
                . Html::endForm()
                . '</li>'
        ),
    ];
    echo MultiMenu::widget(
        [
            'activeCssClass' => 'active',
            'items' => $items,
            'layoutTemplate' => '{multimenu}{brand}',
            'enableIcons'=>true,
            'brandUrl' => 'https://plugins.omaraslam.com',
            'brandLabel'=>'Yii2 Multimenu',
            'activateParents' => true,
            'multimenuOptions' => [
                'theme' => MultiMenu::THEME_BIGDROP,
            ],
        ]
    );

?>

Leftnav Minimal options with brand image

<?php
    use buttflattery\multimenu\MultiMenu;
    $items = [
            ['label' => 'Home', 'url' => ['/site/index']],
            ['label' => 'About', 'url' => ['/site/about']],
            ['label' => 'Contact', 'url' => ['/site/contact']],
            [
                'label' => 'Dropdown',
                'url' => 'javascript:void(0)',
                'items' => [
                    ['label' => 'Level 1  Dropdown A', 'url' => '#'],
                    ['label' => 'Level 1  Dropdown B', 'url' => '#'],
                ],
            ],
            Yii::$app->user->isGuest ? (
                ['label' => 'Login', 'url' => ['/site/login']]
            ) : (
                '<li>'
                . Html::beginForm(['/site/logout'], 'post')
                . Html::submitButton(
                    'Logout (' . Yii::$app->user->identity->username . ')',
                    ['class' => 'btn btn-link logout']
                )
                . Html::endForm()
                . '</li>'
        ),
    ];

    echo MultiMenu::widget(
        [
            'activeCssClass' => 'active',
            'items' => $items,
            'brandLabel' => 'Left Navigation',
            'brandImage' => 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAB+0lEQVR4AcyYg5LkUBhG+1X2PdZGaW3btm3btm3bHttWrPomd1r/2Jn/VJ02TpxcH4CQ/dsuazWgzbIdrm9dZVd4pBz4zx2igTaFHrhvjneVXNHCSqIlFEjiwMyyyOBilRgGSqLNF1jnwNQdIvAt48C3IlBmHCiLQHC2zoHDu6zG1iXn6+y62ScxY9AODO6w0pvAqf23oSE4joOfH6OxfMoRnoGUm+de8wykbFt6wZtA07QwtNOqKh3ZbS3Wzz2F+1c/QJY0UCJ/J3kXWJfv7VhxCRRV1jGw7XI+gcO7rEFFRvdYxydwcPsVsC0bQdKScngt4iUTD4Fy/8p7PoHzRu1DclwmgmiqgUXjD3oTKHbAt869qdJ7l98jNTEblPTkXMwetpvnftA0LLHb4X8kiY9Kx6Q+W7wJtG0HR7fdrtYz+x7iya0vkEtUULIzCjC21wY+W/GYXusRH5kGytWTLxgEEhePPwhKYb7EK3BQuxWwTBuUkd3X8goUn6fMHLyTT+DCsQdAEXNzSMeVPAJHdF2DmH8poCREp3uwm7HsGq9J9q69iuunX6EgrwQVObjpBt8z6rdPfvE8kiiyhsvHnomrQx6BxYUyYiNS8f75H1w4/ISepDZLoDhNJ9cdNUquhRsv+6EP9oNH7Iff2A9g8h8CLt1gH0Qf9NMQAFnO60BJFQe0AAAAAElFTkSuQmCC',
            'brandUrl' => 'http://omaraslam.com',
            'activateParents' => true,
            'layoutTemplate'=>'{multimenu}{brand}',
            'enableIcons'=>true,
            'multimenuOptions' => [
                'theme' => MultiMenu::THEME_LEFTNAV,
                'mobileView' => true,
                MultiMenu::THEME_LEFTNAV => [
                    'position'=>MultiMenu::LEFT_NAV_FIXED,
                    'slimScroll' => [
                        'scrollColor' => 'rgba(0,0,0,0.75)'
                    ]
                ]
            ]
        ]
    );
?>

Dropup menu with custom color theme Asset Class

<?php
    use buttflattery\multimenu\MultiMenu;

    $items = [
            ['label' => 'Home', 'url' => ['/site/index']],
            ['label' => 'About', 'url' => ['/site/about']],
            ['label' => 'Contact', 'url' => ['/site/contact']],
            [
                'label' => 'Dropdown',
                'url' => 'javascript:void(0)',
                'items' => [
                    ['label' => 'Level 1  Dropdown A', 'url' => '#'],
                    ['label' => 'Level 1  Dropdown B', 'url' => '#'],
                ],
            ],
            Yii::$app->user->isGuest ? (
                ['label' => 'Login', 'url' => ['/site/login']]
            ) : (
                '<li>'
                . Html::beginForm(['/site/logout'], 'post')
                . Html::submitButton(
                    'Logout (' . Yii::$app->user->identity->username . ')',
                    ['class' => 'btn btn-link logout']
                )
                . Html::endForm()
                . '</li>'
        ),
    ];

    echo MultiMenu::widget(
        [
            'activeCssClass' => 'active',
            'items' => Yii::$app->menuhelper->getMenuItems('menu_name'),
            'activateParents' => true,
            'brandLabel' => 'Yii2 Multimenu',
            'enableIcons'=>true,
            'brandUrl' => 'https://plugins.omaraslam.com',
            'layoutTemplate'=>'{multimenu}{brand}',
            'multimenuOptions' => [
                'theme' => MultiMenu::THEME_DROPUP,
                'themeColorFile' => \app\assets\DropUpBisqueRed::class,
                'mobileView' => true,
                MultiMenu::THEME_DROPUP => [
                    'transitionEffect' => MultiMenu::ANIMATE_DEFAULT,
                ],
            ],
        ]
    );
?>

Your theme asset class code

<?php
// @codingStandardsIgnoreStart
namespace app\assets;

use buttflattery\multimenu\assetbundles\bs3\ThemeDropUpAsset;

class DropUpBisqueRed extends ThemeDropUpAsset
{
    //@codingStandardsIgnoreEnd

    public function init()
    {
        parent::init();
        array_push($this->css, '/css/theme/dropup/bisque-red.css');
    }
}

Menu items from Database

A helper component buttflattery\multimenu\helpers\MenuHelper is added that come in handy if you want to just add all the menu items in the database table and leave the rest on this component to generate the items array for the menu.

If you dont have a menu table added yet you can run the migration and use the model provided buttflattery\multimenu\models\Menu.

Running migrations

Run the following command on terminal to run the migrations

php ./yii migrate/up --migrationPath=@vendor/buttflattery/yii2-multimenu/src/migrations

+-----------+-------------+------+-----+---------+----------------+
| Field     | Type        | Null | Key | Default | Extra          |
+-----------+-------------+------+-----+---------+----------------+
| id        | int(11)     | NO   | PRI | NULL    | auto_increment |
| label     | varchar(50) | NO   |     | NULL    |                |
| link      | text        | YES  |     | NULL    |                |
| parent_id | int(11)     | YES  |     | NULL    |                |
+-----------+-------------+------+-----+---------+----------------+
Configure the Component

Open config/web.php if you are using yii2-basic or the common/config/main.php if you are using advance-app and add the following under the components array.

'components' => [
    'menuhelper' => [
        'class' => 'buttflattery\multimenu\helpers\MenuHelper',
        'model' => 'buttflattery\multimenu\models\Menu',
    ],

If you wish to use your custom model and have a menu table already you can provide your own model namespace and set the field names appropriately for the component to work correctly. See below for a full set of options you can configure for the component.

'components' => [
    'menuhelper' => [
        'class' => 'buttflattery\multimenu\helpers\MenuHelper',
        'model' => 'app\models\Menus',
        'linkField'=>'menu_link',
        'labelField'=>'menu_name',
        'idField'=>'menu_id',
        'parentIdField'=>'menu_parent_id',
    ],

Now you can call the function getMenuItems(orderByField) to get the $items array like below.

<?php
    use buttflattery\multimenu\MultiMenu;

    echo MultiMenu::widget(
        [
            'activeCssClass' => 'active',
            'items' => Yii::$app->menuhelper->getMenuItems(),
            'layoutTemplate' => '{multimenu}{brand}',
            'enableIcons'=>true,
            'brandUrl' => 'https://plugins.omaraslam.com',
            'brandLabel'=>'Yii2 Multimenu',
            'activateParents' => true,
            'multimenuOptions' => [
                'theme' => MultiMenu::THEME_BIGDROP,
            ],
        ]
    );

?>

Available Constants


  /**
  * For use with leftnav `position` option
  */
  const LEFT_NAV_FIXED = 'fixed';
  const LEFT_NAV_ABSOLUTE = 'absolute';
  const LEFT_NAV_DEFAULT = 'default';

  /**
   * Supported Transition effects by animate.css
   * https://daneden.github.io/animate.css/
  */
  const ANIMATE_BOUNCE_IN = 'bounceIn';
  const ANIMATE_BOUNCE_IN_DOWN = 'bounceInDown';
  const ANIMATE_BOUNCE_IN_UP = 'bounceInUp';
  const ANIMATE_BOUNCE_IN_LEFT = 'bounceInLeft';
  const ANIMATE_BOUNCE_IN_RIGHT = 'bounceInRight';

  const ANIMATE_FADE_IN = 'fadeIn';
  const ANIMATE_FADE_IN_DOWN = 'fadeInDown';
  const ANIMATE_FADE_IN_DOWN_BIG = 'fadeInDownBig';
  const ANIMATE_FADE_IN_LEFT = 'fadeInLeft';
  const ANIMATE_FADE_IN_LEFT_BIG = 'fadeInLeftBig';
  const ANIMATE_FADE_IN_RIGHT = 'fadeInRight';
  const ANIMATE_FADE_IN_RIGHT_BIG = 'fadeInRightBig';

  const ANIMATE_FLIP = 'flip';
  const ANIMATE_FLIP_IN_X = 'flipInX';
  const ANIMATE_FLIP_IN_Y = 'flipInY';

  const ANIMATE_LITE_SPEED_IN = 'lightSpeedIn';

  const ANIMATE_ROTATE_IN = 'rotateIn';
  const ANIMATE_ROTATE_IN_DOWN_LEFT = 'rotateInDownLeft';
  const ANIMATE_ROTATE_IN_DOWN_RIGHT = 'rotateInDownRight';
  const ANIMATE_ROTATE_IN_UP_LEFT = 'rotateInUpLeft';
  const ANIMATE_ROTATE_IN_UP_RIGHT = 'rotateInUpRight';

  const ANIMATE_SLIDE_IN_UP = 'slideInUp';
  const ANIMATE_SLIDE_IN_DOWN = 'slideInDown';
  const ANIMATE_SLIDE_IN_LEFT = 'slideInLeft';
  const ANIMATE_SLIDE_IN_RIGHT = 'slideInRight';

  const ANIMATE_ZOOM_IN = 'zoomIn';
  const ANIMATE_ZOOM_IN_UP = 'zoomInUp';
  const ANIMATE_ZOOM_IN_DOWN = 'zoomInDow';
  const ANIMATE_ZOOM_IN_LEFT = 'zoomInLeft';
  const ANIMATE_ZOOM_IN_RIGHT = 'zoomInRight';

  /**
   * delay types for `transitionDelay` option
   * under the menu specific options
   */
  const ANIMATE_DEFAULT = '';
  const ANIMATE_FAST = 'fast';
  const ANIMATE_FASTER = 'faster';
  const ANIMATE_SLOW = 'slow';
  const ANIMATE_SLOWER = 'slower';

  /**
   * Waves plugin effects http://fian.my.id/Waves/#examples
   * used for the option `wavesEffect`
   */
  const WAVES_TYPE_CIRCLE = 'waves-circle';
  const WAVES_TYPE_DEFAULT = 'default';

  const WAVES_LIGHT = 'waves-light';
  const WAVES_RED = 'waves-red';
  const WAVES_PINK = 'waves-pink';
  const WAVES_PURPLE = 'waves-purple';
  const WAVES_DEEP_PURPLE = 'waves-deep-purple';
  const WAVES_INDIGO = 'waves-indigo';
  const WAVES_BLUE = 'waves-blue';
  const WAVES_LIGHT_BLUE = 'waves-light-blue';
  const WAVES_CYAN = 'waves-cyan';
  const WAVES_TEAL = 'waves-teal';
  const WAVES_GREEN = 'waves-green';
  const WAVES_LIGHT_GREEN = 'waves-light-green';
  const WAVES_LIME = 'waves-lime';
  const WAVES_YELLOW = 'waves-yellow';
  const WAVES_AMBER = 'waves-amber';
  const WAVES_ORANGE = 'waves-orange';
  const WAVES_DEEP_ORANGE = 'waves-deep-orange';
  const WAVES_BROWN = 'waves-brown';
  const WAVES_GREY = 'waves-grey';
  const WAVES_BLUE_GREY = 'waves-blue-grey';
  const WAVES_BLACK = 'waves-black';

  /**
   * Themes available used for the `theme` option
   * under `multimenuOptions` option
   */
  const THEME_BIGDROP = 'bigdrop';
  const THEME_LEFTNAV = 'leftnav';
  const THEME_DROPUP = 'dropup';
Who do I talk to?
  • buttflattery@gmail.com
  • yii2plugins@omaraslam.com

[wiki] Yii2 - Upgrading to Bootstrap 4

$
0
0

Yii2 - Converting from Bootstrap3 to Bootstrap4

This article has been written because while conversion is a largely pain-free process, there are some minor issues. These are not difficult to solve, but it is not immediately obvious where the problem lies.

1 - Install Bootstrap4 My preference is to simply use composer. Change composer.json in the root of your project:

  • find the line that includes Bootstrap3.
  • Copy the line, and change the new line:

    • change bootstrap to bootstrap4
    • Now head over to https://github.com/yiisoft/ - the Yii2 repository on Github
    • Change the version string to that version number, and also change the ~ to ^
    • After this, you should have something like this below, maybe with higher version numbers:

      "yiisoft/yii2-bootstrap" : "~2.0.6", "yiisoft/yii2-bootstrap4" : "^2.0.8",

  • Save the file, then run 'composer update'
  • Use your IDE, text editor or whatever other means you have at your disposal to find all occurrences where bootstrap is used and change it bootstrap4. My suggestion is to search for the string yii\bootstrap\ and change it to yii\bootstrap4\. However, be careful - your IDE may require the backslash to be escaped. For example, Eclipse will find all files with the string easily, but the search string must have double-backslashes, while the replacement string must be left as single ones.
  • Now run all your tests and fix the problems that have arisen. Most of the failures will come from the fact that the Navbar no longer works, most likely. It's still there, just being rendered differently, and in my case it was invisible. This is because Bootstrap4 has changed some elements of the navbar. In my case, 14 tests failed - many of which failed due to the use of navbar content in some manner, such as looking for the Login link to infer whether the user is logged in or not.
    • You're not going to fix these issues without understanding them, so take a look at https://getbootstrap.com/docs/4.0/migration/. In particular, look at what has changed regarding the Navbars. The most meaningful is that Bootstrap4 no longer specifies a background, where Bootstrap3 did.
    • Open up frontend/viewslayouts/main.php in your editor, then look at your site in the browser. In my case no navbar, except for the Brand, and that is because I changed this from what was delivered as part of the Yii2 template, and it included a background. Since the rest of it was standard, there was nothing else - no ribbon strip, and no menu entries, although mousing into the area would show the links were there and could be clicked.
      • Find the line that starts with NavBar::begin and look at it's class options. In my case they were the original: 'class' => 'navbar-inverse navbar-fixed-top'
        • As I said before, no background is included, so add one: bg-dark - and check again. Now there's the ribbon back again, but no menu items.
        • Right-click on the ribbon and select "Inspect Element", or do whatever you have to do in your browser to inspect the page source. Looking at that starts to give you clues over what the navbar is doing. Looking at that, and referring back to the Bootstrap4 migration guide, I had the impression that neither navbar-inverse nor navbar-fixed-top were doing anything. So I removed those, and when refreshing the page, confirmed there were no changes.
        • More reading on the Bootstrap website gave me the bg-dark I mentioned earlier, and for the text, navbar-light or navbar-dark produced results.
        • now I had no menu items, but I did have a button that expanded the menu. Inspecting it's properties told me it was 'navbar-toggler', and the Bootstrap website told me it new to Bootstrap4, while it and was collapsed by default, 'navbar-expand' would expand it by default. That's cool - I reckon I'm going to add a setting for logged-in users that let them choose which they prefer. In the end, I opted for navbar-expand-md, which keeps it expanded unless the screen width is tight.

At the end of all this, I had the class line changed to something which gave me a navbar very similar to the original:

        //Bootstrap3: 'class' => 'navbar-inverse navbar-fixed-top',
        //Changed for Bootstrap4: 
        'class' => 'navbar navbar-expand-md navbar-light bg-dark',

So, that fixed my navbar. Running my tests pointed me to other problems, but I won't go into those. Now that you know the process, you can find all your errors and fix them in the same way - I need to fix problems in some of my forms where the action buttons are now being rendered in a space too small to be visible. Somehow, those problems don't seem quite so insurmountable anymore.

[extension] pingcrm-yii2

$
0
0

Ping CRM on Yii 2

  1. Installation
  2. Running tests
  3. Requirements
  4. Credits

A Yii 2 demo application to illustrate how Inertia.js works.

This application is a port of the original Ping CRM written in Laravel and based on the Yii 2 Basic Project Template.

screenshot.png

Installation

Clone the repo locally:

git clone https://github.com/tbreuss/pingcrm-yii2 pingcrm-yii2
cd pingcrm-yii2

Install PHP dependencies:

composer install

Install NPM dependencies:

npm ci

Build assets:

npm run dev
npm run css-dev

Create an SQLite database. You can also use another database (MySQL, Postgres), simply update your configuration accordingly.

touch database/database.sqlite

Run database migrations:

php yii migrate

Run database seeder:

php yii db/seed

Run the dev server (the output will give the address):

php yii serve

You're ready to go! Visit Ping CRM in your browser, and login with:

  • Username: johndoe@example.com
  • Password: secret

Running tests

To run the Ping CRM tests, run:

(to be done)

Requirements

  • PHP >= 5.6.0
  • SQLite

Credits

  • Original work by Jonathan Reinink (@reinink) and contributors
  • Port to Yii 2 by Thomas Breuss (@tbreuss)

[extension] yiiplus/yii2-elasticsearch

$
0
0

logo-elastic.svg

Elasticsearch Query and ActiveRecord for Yii 2

  1. Requirements
  2. Installation
  3. Configuration

This extension provides the elasticsearch integration for the Yii framework 2.0. It includes basic querying/search support and also implements the ActiveRecord pattern that allows you to store active records in elasticsearch.

For license information check the LICENSE-file.

Documentation is at docs/guide/README.md.

Latest Stable Version Total Downloads Build Status

Requirements

Dependent on the version of elasticsearch you are using you need a different version of this extension.

  • Extension version 2.0.x works with elasticsearch version 1.0 to 4.x.
  • Extension version 2.1.x requires at least elasticsearch version 5.0.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist yiisoft/yii2-elasticsearch:"~2.0.0"

or add

"yiisoft/yii2-elasticsearch": "~2.0.0"

to the require section of your composer.json.

Configuration

To use this extension, you have to configure the Connection class in your application configuration:

return [
    //....
    'components' => [
        'elasticsearch' => [
            'class' => 'yii\elasticsearch\Connection',
            'nodes' => [
                ['http_address' => '127.0.0.1:9200'],
                // configure more hosts if you have a cluster
            ],
        ],
    ]
];

[extension] yiiplus/yii2-websocket

$
0
0

yii2-websocket

  1. 驱动支持
  2. 安装
  3. 基本使用

在 yii2 下运行 WebSocket 服务。

Latest Stable Version Total Downloads License

驱动支持

安装

安装此扩展程序的首选方法是通过 composer.

编辑运行

php composer.phar require --prefer-dist yiiplus/yii2-websocket "^1.0.0"

或添加配置到项目目录下的composer.json文件的 require 部分

"yiiplus/yii2-websocket": "^1.0.0"

基本使用

每个 channel 的功能都需要定义一个单独的类。例如,如果你需要为指定客户端推送一条消息,则该类可能如下所示:

namespace xxx\channels;

class PushMessageChannel extends BaseObject implements \yiiplus\websocket\ChannelInterface
{
	public function execute($fd, $data)
	{
		return [
			$fd, // 第一个参数返回客户端ID,多个以数组形式返回
			$data // 第二个参数返回需要返回给客户端的消息
		];
	}

	public function close($fd)
	{
		return;
	}
}

以下是从客户端发送消息的方法:

Yii::$app->websocket->send(['channel' => 'push-message', 'message' => '用户 xxx 送了一台飞机!']);

执行任务的确切方式取决于使用的驱动程序。 大多数驱动程序可以使用控制台命令运行,组件需要在应用程序中注册。

此命令启动一个守护进程,该守护进程维护一个 WebSocket Server,根据客户端发来的数据,处理相关 channel 的任务:

yii websocket/start

有关驱动程序特定控制台命令及其选项的更多详细信息,请参阅 文档


[extension] tebe/yii2-inertia

$
0
0

Inertia.js Yii 2 Adapter

  1. Demo
  2. Installation

With Inertia you are able to build single-page apps using classic server-side routing and controllers, without building an API.

Demo

http://pingcrm-yii2.tebe.ch

Installation

Composer require dependency:

composer require tebe/yii2-inertia:dev-master

Edit config/web.php:

    'bootstrap' => ['inertia'],
    'components' => [
      'inertia' => [
        'class' => 'tebe\inertia\Inertia'
      ]
    ]  

Extend controllers from tebe\inertia\web\Controller:

<?php

namespace app\controllers;

use tebe\inertia\web\Controller;
use yii\filters\AccessControl;

class DemoController extends Controller
{
    public function actionIndex()
    {
        $params = [
            'data' => [],
            'links' => []
        ];
        return $this->inertia('demo/index', $params);
    }
}

Implement client using one of the official adapters like Vue.js, React, or Svelte.

Visit inertiajs.com to learn more.

[extension] sjaakp/yii2-swiper

$
0
0

Yii2-swiper

  1. Installation
  2. Using Yii2-swiper
Swiper widget for Yii2

Latest Stable Version Total Downloads License

This is a widget and associated behavior for ActiveRecords in the Yii 2.0 PHP Framework. It allows the user to jump to neighbouring records by means of clicking, touch swiping, or using the left and right arrow keys.

Yii2-swiper assumes that your site is using a Font Awesome icon font (v3 or higher). Bootstrap 4 is recommended.

A demonstration of yii2-swiper is here.

Installation

The preferred way to install yii2-swiper is through Composer. Either add the following to the require section of your composer.json file:

"sjaakp/yii2-swiper": "*"

Or run:

composer require sjaakp/yii2-swiper "*"

You can manually install yii2-swiper by downloading the source in ZIP-format.

Using Yii2-swiper

Yii2-swiper consists of two classes: PrevNextBehavior and Swiper in namespace sjaakp\swiper.

PrevNextBehavior

This is a Behavior for an ActiveRecord. It supplies the owning ActiveRecord with two methods:

  • getPrev(): Returns an ActiveQuery to the previous record.
  • getNext(): Returns an ActiveQuery to the next record.

In other words, the owning ActiveRecord now has two virtual properties:

  • $prev: the previous record, or null if the current record is the first.
  • $next: the next record, or null if the current record is the last.

PrevNextBehavior has two properties:

  • $attribute string Name of the ActiveRecord attribute that defines the ordering. Has to be set.
  • $sort SORT_ASC|SORT_DESC Sets whether the order is incrementing or decrementing. Default: SORT_ASC (incrementing).

PrevNextBehavior can be added to an ActiveRecord like so:

<?php
use sjaakp\swiper\PrevNextBehavior;

class Event extends \yii\db\ActiveRecord
{
    // ...    
    public function behaviors()
    {
        return [
            [
                'class' => PrevNextBehavior::class,
                'attribute' => 'date',
            ]
        ];
    }
    // ...
}
Swiper

This is a Widget, rendering buttons to the previous and next page (if available). It also implements the code to handle touch swiping and keyboard input. Its $model property should be set to an instance of an ActiveRecord having PrevNextBehavior.

Swiper's other properties are:

  • $labelAttribute string Name of the attribute providing the label text for the buttons. Must be set.
  • $shortLabelAttribute null|string Name of the attribute providing the short label text for the buttons. Optional. The short label appears when the screen width is smaller than the value indicated by $breakpoint. Default: null (no short labels).
  • $breakpoint string The Bootstrap 4 breakpoint defining when short labels will appear. Default: 'sm'.
  • $url string The base URL of the button links. Default: 'view'.
  • $swipeId null|string The HTML-id of the element sensible to touch swiping. If null (default) it is the <body> element.
  • $options array HTML options for the surrounding <nav> element.
  • $registerLinkTags bool Whether to register link tags in the HTML header for previous and next page. Default: false, to avoid conflicts with other widgets.

In a view file, say event\view, Swiper could be employed along these lines:

<?php
    use sjaakp\swiper\Swiper
?>
<h1>...</h1>
...
<?= Swiper::widget([
    'model' => $model,
    'labelAttribute' => 'title',
    // 'url' => 'view',       // default 
    'registerLinkTags' => true
]) ?>
... other view code ...

[news] Sphinx extension 2.0.13 released

[extension] matvik/yii2-model-gallery

$
0
0

Yii 2 model images gallery - behavior and widget

  1. Installation
  2. Usage

This extension implements the behavior and widget for a set of images related to a particular model (product, user, etc.). Ajax Widget

Installation

The preferred way to install this extension is through composer.

Either run

composer require --prefer-dist matvik/yii2-model-gallery "*"

or add

"matvik/yii2-model-gallery": "*"

to the require section of your composer.json file.

Usage

Documentation is at:

English - docs/GUIDE-en.md.

Ukrainian - docs/GUIDE-uk.md.

[extension] bestyii/yii2-openapi-reader

[extension] bestyii/yii2-gii-rest

[news] Shell extension 2.0.3 released

$
0
0

We are very pleased to announce the release of Shell extension version 2.0.3. This version adds compatibility with symfony/var-dumper 5.x.


[extension] yii2-app-vue

$
0
0

yii2-app-vue

  1. for yii2 web application width vueJs
  2. Installation
  3. Development Setup
  4. Local Development Server
  5. Directory components vuejs to:

for yii2 web application width vueJs

Yii and VueJs

Installation

The preferred way to install this extension is through composer.

Either run

composer create-project aki/yii2-app-vue

or add

"aki/yii2-app-vue": "*"

to the require section of your composer.json file.

Development Setup

# install deps
npm install

# build dist files
npm run build

# serve examples at localhost
npm run dev

# serve examples at localhost --watch
npm run watch

Local Development Server

If you have PHP installed locally and you would like to use PHP's built-in development server to serve your application, you may use the serve yii command. This command will start a development server at http://localhost:8000: php yii serve

Directory components vuejs to:

  assets/             contains assets definition
  commands/           contains console commands (controllers)
  config/             contains application configurations
  controllers/        contains Web controller classes
  mail/               contains view files for e-mails
  models/             contains model classes
  runtime/            contains files generated during runtime
  tests/              contains various tests for the basic application
  vendor/             contains dependent 3rd-party packages
  views/              contains view files for the Web application
    assets/           contains assets files
        js/           contains js files
         components/  contains components vue files
        sass/         contains scss files
  web/                contains the entry script and Web resources

[news] Friendly exception 1.0.0 released

$
0
0

First Yii 3 package is released. Friendly Exception is an exception interface that provides a friendly name and a possible solution. Error handlers may consider the interface to render additional information right at the error screen.

The package is framework-independent so could be used with any PHP code.

Check it out

[news] Twig extension 2.4.0 released

$
0
0

We are very pleased to announce two releases of Twig extension.

Version 2.4.0 upgrades Twig to 3.x and adds a built-in function for message translation:

{{ t('app', 'Hello, world!') }}

[news] Redis extension 2.0.12 released

$
0
0

We are very pleased to announce the release of Redis extension version 2.0.12.

This version fixes some bugs, adds ability to connect via SSL, and increases frequency of lock tries on mutex timeout.

See the CHANGELOG for details.

[news] Yii 2.0.33

$
0
0

We are very pleased to announce the release of Yii Framework version 2.0.33. Please refer to the instructions at https://www.yiiframework.com/download/ to install or upgrade to this version.

Version 2.0.33 is a minor release of Yii 2.0 that fixes 22 issues and makes 4 enhancements:

  • Allow yii\data\ArrayDataProvider to control the sort flags for sortModels through
    yii\data\Sort::sortFlags property.
  • Use Instance::ensure() to initialize UrlManager::$cache.
  • Add StringValidator::$strict that can be turned off to allow any scalars.
  • Actions can now have bool typed params bound.

Thanks to all Yii community members who contribute to the framework, translators who keep documentation translations up to date and community members who answer questions at forums.

There are many active Yii communities so if you need help or want to share your experience, feel free to join them.

A complete list of changes can be found in the CHANGELOG.

Viewing all 2943 articles
Browse latest View live