Git Product home page Git Product logo

yii2-helpers's Introduction

Krajee Logo
yii2-helpers
Donate

Latest Stable Version Latest Unstable Version License Total Downloads Monthly Downloads Daily Downloads

This extension is a collection of useful helper functions for Yii Framework 2.0.

Html Class

VIEW DEMO

This class extends the Yii Html Helper to incorporate additional HTML markup functionality and features available in Bootstrap 3.x / 4.x. The helper functions available in this class are:

  • Icon
  • Label
  • Badge
  • Page Header
  • Well
  • Close Button
  • Caret
  • Jumbotron
  • Abbreviation
  • Blockquote
  • Address
  • List Group
  • Panel
  • Media
  • Media List
  • Checkbox Button Group
  • Radio Button Group

Enum Class

VIEW DEMO

This class extends the Yii Inflector Helper with more utility functions for Yii developers. The helper functions available in this class are:

  • Is Empty
  • In Array
  • Properize
  • Time Elapsed
  • Time To String
  • Time Remaining
  • Format Bytes
  • Number to Words
  • Year List
  • Month List
  • Day List
  • Date List
  • Time List
  • Boolean List
  • Get PHP Data Type
  • Array to HTML Table
  • IP Address

Demo

You can see a demonstration here on usage of these functions with documentation and examples.

Installation

The preferred way to install this extension is through composer.

Note: Check the composer.json for this extension's requirements and dependencies. Read this web tip /wiki on setting the minimum-stability settings for your application's composer.json.

Either run

$ php composer.phar require kartik-v/yii2-helpers "dev-master"

or add

"kartik-v/yii2-helpers": "dev-master"

to the require section of your composer.json file.

Usage

// add this to your code to use these classes
use kartik\helpers\Html;
use kartik\helpers\Enum;

// examples of usage
echo Html::icon('cloud');
echo Enum::properize('Chris');

License

yii2-helpers is released under the BSD-3-Clause License. See the bundled LICENSE.md for details.

yii2-helpers's People

Contributors

cshehadi avatar daveferger avatar dkushnikov avatar dungphanxuan avatar fingal56 avatar gvasilopulos avatar henkkao avatar kartik-v avatar lherry avatar maxlord avatar mbenedek avatar monghuz avatar moysoft avatar nepster-web avatar richweber avatar toriphes avatar tuyakhov avatar ulrichmathes avatar viqtor avatar wbraganca avatar xzaero avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yii2-helpers's Issues

Html::listGroup not generating the correct output

Using this code from the docs:

Html::listGroup([
    [
        'content' => 'Cras justo odio',
        'url' => '#',
        'badge' => '14'
    ],
    [
        'content' => 'Dapibus ac facilisis in',
        'url' => '#',
        'badge' => '2'
    ],
    [
        'content' => 'Morbi leo risus',
        'url' => '#',
        'badge' => '1'
    ],
], [], 'ul', 'li');

Generates this:

<ul class="list-group">
    <a class="list-group-item" href="#"><span class="badge">14</span>Cras justo odio</a>
    <a class="list-group-item" href="#"><span class="badge">2</span>Dapibus ac facilisis in</a>
    <a class="list-group-item" href="#"><span class="badge">1</span>Morbi leo risus</a>
</ul>

But should be this:

<ul class="list-group">
    <li class="list-group-item"><a href="#"><span class="badge">14</span>Cras justo odio</a></li>
    <li class="list-group-item"><a href="#"><span class="badge">2</span>Dapibus ac facilisis in</a></li>
    <li class="list-group-item"><a href="#"><span class="badge">1</span>Morbi leo risus</a></li>
</ul>

Even without the $options, $tag and $itemTag variables, generates the incorrect output.

Something wrong here

-------Html.php-------------

protected static function getPanelContent($content, $type)
{
    $out = ArrayHelper::getValue($content, $type, '');
    //return Enum::isEmpty($out) ? $out . "\n" : '';
    return !Enum::isEmpty($out) ? $out . "\n" : '';
}

Panel 'panel-body' wrap code missing

The \kartik\helpers\Html::panel() method phpdoc implies the 'body' option will be wrapped with a <div class="panel-body">...</div> yet there does not seem to be any code performing this.
Is this on purpose as the panel-body wrap should certainly be optional?

userIP function should be deprecated

For a while now, Yii2 supports getting the users' IP from request headers in a secure manner.

The current implementation of Enum::userIP() is not secure (since it blindly trusts headers) and therefore should not be used.

Furthermore it directly uses the global $_SERVER variable which is is considered bad practice.

If a custom implementation is needed (for filtering local IPs), in my opinion it should at the very least use the Yii2 request object.
Note that in most cases filtering local IPs isn't needed if the request object has been properly configured to trust the correct headers.

Item in Html::radioButtonGroup is ignored

Hello!
I'm trying to use radioButtonGroup like this

echo Html::radioButtonGroup('status', $searchModel->status,
    [
        "" => 'All',
        1 => 'Correct',
        0 => 'Neutral',
        -1 => 'Incorrect'
    ],
    [
        'style' => 'white-space: nowrap',
        'encode' => false,
        'item' => function ($index, $label, $name, $checked, $value) {
        $radioButton = Html::radio($name, $checked, [
            'value' => $value,
        ]);
        return Html::label($radioButton . $label, null, [
            'class' => 'btn' . ($checked ? ' active' : '') . ($value > 0 ? ' btn-success' : ($value < 0 ? ' btn-danger' : ' btn-default')),
        ]);
        }
    ]
)

Closure named 'item' is ignored and even die() inside function does not stop execution.
Similar method in ActiveField class work fine. I think it's a bug because I found such code in its definition:
if (!isset($options['item'])) {
This code is missing in Html class and 'item' is rewritten and forgotten by application.

Please respond and/or fix this in your plugin. Thanks!

Unsupported operand types

Steps to reproduce the issue

  1. Upgrade PHP from 7.0 to 7.2
  2. Upgrade to kartik-v/yii2-helpers 1.3.9 (from 1.3.8 highly likely)

Expected behavior and actual behavior

I had this code with ommited optional args for HTML::listGroup and it worked well before:

echo Html::panel([
        'heading' => 'Тесты:',
        'body' => HTML::listGroup($tabBody,[],'ul','li'),
        'headingTitle' => true
]);

After update of php and Helper module this code with (!!!) ommiting optional args (!!!) produces a bug.

Unsupported operand types
A non-numeric value encountered

Screenshot_2

The fix is easy --> change code to fill in optional args like that:

echo Html::panel([
        'heading' => 'Тесты:',
        'body' => HTML::listGroup($tabBody,[],[],[],'ul','li'),
        'headingTitle' => true
]);

That`s now a big error but really annoying to redo the code ))
What i am did wrong? Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.