首页 > 其他分享 >Yii2 小部件使用(bootstrap5)

Yii2 小部件使用(bootstrap5)

时间:2024-04-09 17:12:48浏览次数:21  
标签:Yii2 yii 部件 label options bootstrap5 btn class

Yii2 小部件使用(bootstrap5)

修改web.php assetManager

'components' => [
        'assetManager' => [
            'appendTimestamp' => true,
            'class' => 'yii\web\AssetManager',
            'bundles' => [
                'yii\web\JqueryAsset' => [
                    'js' => [
                        '/js/jquery.min.js'
                    ]
                ],
                // 禁用boostrap.css
                'yii\bootstrap5\BootstrapAsset' => [
                    'css' => ['/bootstrap5/css/bootstrap.min.css']
                ],
                // 禁用boostrap.js
                'yii\bootstrap5\BootstrapPluginAsset' => [
                    'js' => ['/bootstrap5/js/bootstrap.bundle.min.js']
                ]
            ]
        ],
]

折叠菜单

img2png

use yii\bootstrap5\Accordion;

echo Accordion::widget([
'items' => [
[
'label' => '标签一',
'content' => '内容一',
],
[
'label' => '标签二',
'content' => '内容二',
'options' => ['class' => 'panel-warning'],
],
[
'label' => '标签三',
'content' => '内容三',
'options' => ['class' => 'panel-danger'],
],
]
]);

消息提示

img3png

use yii\bootstrap5\Alert;

echo Alert::widget([
    'body' => "消息内容",
    'options' => ['class' => 'alert-success'],//alert-success|alert-danger|alert-warning
    'closeButton' => [
        'label' => '关闭',
        'tag' => 'a',
        'class' => ['widget' => 'btn btn-outline-warning'],
        'style' => [
            'position' => 'absolute',
            'top' => '.5rem',
            'right' => '.5rem'
        ],
    ]
]);

按钮

img4png

use yii\bootstrap5\Button;

echo Button::widget([
    'label' => '按钮',
    'options' => ['class' => 'btn btn-default'],//btn-lg|btn-default|btn-success|btn-danger|btn-warning
]);

面包屑导航

imgpng

use yii\bootstrap5\Breadcrumbs;

echo Breadcrumbs::widget([
    'homeLink' => ['label' => 'Home', 'url' => '#'],
    'links' => [
        ['label' => 'Library', 'url' => '#'],
        ['label' => 'Data']
    ]
]);

下拉按钮

imgpng

use yii\bootstrap5\ButtonDropdown;

echo ButtonDropdown::widget([
    'label' => 'Action',
    //'options' => ['class' => 'btn-primary', 'style' => 'font-size:14px;'], // 设置按钮的 CSS 类和样式
    'buttonOptions' => ['class' => 'btn btn-success'], // 设置按钮的 CSS 类
    'dropdown' => [
        'items' => [
            ['label' => 'DropdownA', 'url' => '/'],
            ['label' => 'DropdownB', 'url' => '#'],
        ],
    ],
]);

按钮组

imgpng

use yii\bootstrap5\ButtonGroup;

echo ButtonGroup::widget([
    'buttons' => [
        ['label' => '按钮A'],
        ['label' => '按钮B'],
        ['label' => '隐藏按钮C', 'visible' => false],
    ],
    'options'=>['class'=>'btn btn-primary']
]);

按钮工具栏

imgpng

use yii\bootstrap5\ButtonToolbar;

echo ButtonToolbar::widget([
    'buttonGroups' => [
        [
            'buttons' => [
                ['label' => '1', 'options' => ['class' => ['btn-secondary']]],
                ['label' => '2', 'options' => ['class' => ['btn-secondary']]],
                ['label' => '3', 'options' => ['class' => ['btn-secondary']]],
                ['label' => '4', 'options' => ['class' => ['btn-secondary']]]
            ],
             'class' => ['mr-2']
        ],
        [
            'buttons' => [
                ['label' => '5', 'options' => ['class' => ['btn-secondary']]],
                ['label' => '6', 'options' => ['class' => ['btn-secondary']]],
                ['label' => '7', 'options' => ['class' => ['btn-secondary']]]
            ],
            'class' => ['mr-2']
        ],
        [
            'buttons' => [
                ['label' => '8', 'options' => ['class' => ['btn-secondary']]]
            ]
        ]
    ]
]);

幻灯片

imgpng

use yii\bootstrap5\Carousel;

echo Carousel::widget([
    'items' => [
        [
            'content' => '<img src="https://via.placeholder.com/800x400?text=First+slide" class="d-block w-100">',
            'caption' => '<h5>First slide label</h5><p>Nulla vitae elit libero, a pharetra augue mollis interdum.</p>',
            'captionOptions' => [
                'class' => ['d-md-block']
            ],
            'options'=>[]
        ],
        [
            'content' => '<img src="https://via.placeholder.com/800x400?text=Second+slide" class="d-block w-100">',
            'caption' => '<h5>Second slide label</h5><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>',
            'captionOptions' => [
                'class' => ['d-md-block']
            ]
        ],
        [
            'content' => '<img src="https://via.placeholder.com/800x400?text=Third+slide" class="d-block w-100">',
            'caption' => '<h5>Third slide label</h5><p>Praesent commodo cursus magna, vel scelerisque nisl consectetur.</p>',
            'captionOptions' => [
                'class' => ['d-md-block']
            ]
        ]
    ]
]);

表单

imgpng

<?php
use yii\base\DynamicModel;
use yii\bootstrap5\ActiveForm;
?>

<?php $form = ActiveForm::begin([
    'id' => 'login-form',
    'enableClientValidation' => false,
//    'fieldConfig' => [
//        'template' => "<div class='col-sm-2 text-right'>{label}</div><div class='col-sm-10'>{input}\n{hint}\n{error}</div>",
//    ],
]); ?>
<?php
$model = new DynamicModel(['username', 'password','status', 'role_id']);
$model->username = 'zhangsan';
$model->password = '123456';
$model->status = 1;
$model->role_id = 2;
?>
<?= $form->field($model, 'username')->label('账号')->textInput()->hint('注意:账号全字母'); ?>
<?= $form->field($model, 'password')->label('密码')->passwordInput(); ?>
<?= $form->field($model, 'status')->label('状态')->radioList([1=>'正常',0=>'禁用']); ?>
<?= $form->field($model, 'role_id')->label('角色')->dropDownList(['1'=>'管理员',2=>'用户']) ?>

<div class="box-footer">
    <div class="col-sm-12 text-center">
        <button class="btn btn-primary" type="button" onclick="submitForm()">保存</button>
        <span class="btn btn-white" onclick="history.go(-1)">返回</span>
    </div>
</div>
<?php ActiveForm::end(); ?>

分页类

imgpng

controller

public function actionIndex()
    {
        $query = Admin::find()->where(['status' => 1]);
        $countQuery = clone $query;
        $pagination = new Pagination(['totalCount' => $countQuery->count(),'pageSize' => 10]);
        $models = $query->offset($pagination->offset)
            ->limit($pagination->limit)
            ->all();

        return $this->render('index', [
            'models' => $models,
            'pagination' => $pagination,
        ]);
    }

view

<?php
use yii\widgets\LinkPager;
?>

<?php
//循环展示数据
foreach ($models as $model) {
    echo "<li>".$model['id'].' | ' .$model['username']. ' | ' .$model['password']."</li>";
}
?>

<?= LinkPager::widget([
    'pagination' => $pagination,
    'nextPageLabel' => '下一页',
    'prevPageLabel' => '上一页',
    'firstPageLabel' => '首页',
    'lastPageLabel' => '尾页',
    'linkContainerOptions' => ['class' => 'page-item'],
    'linkOptions' => ['class' => 'page-link'],
    'disabledListItemSubTagOptions' => [
        'tag' => 'a',
        'href' => 'javascript:;',
        'tabindex' => '-1',
        'class' => 'page-link'
    ],
]);?>

模态框

imgpng

use yii\bootstrap5\Modal;

Modal::begin([
    'title' => 'Modal title',
    'toggleButton' => ['label' => 'click me'],
]);
echo '<p>Woohoo, you\'re reading this text in a modal!</p>';
Modal::end();

导航条

imgpng

use yii\bootstrap5\NavBar;
use yii\bootstrap5\Nav;

NavBar::begin(['brandLabel' => 'NavBar Test']);
echo Nav::widget([
    'items' => [
        ['label' => 'Home', 'url' => ['/site/index']],
        ['label' => 'About', 'url' => ['/site/about']],
    ],
    'options' => ['class' => 'navbar-nav'],
]);
NavBar::end();

侧边栏

imgpng

use yii\bootstrap5\Nav;
use yii\bootstrap5\Offcanvas;

Offcanvas::begin([
    'toggleButton' => [
        'class' => ['btn', 'btn-primary'],
        'label' => 'Launch demo offcanvas'
    ],
    'placement' => Offcanvas::PLACEMENT_END,
    'backdrop' => true,
    'scrolling' => true
]);

echo '<p>Woohoo, you\'re reading this text in an offcanvas!</p>';

Offcanvas::end();

悬浮层

imgpng

use yii\bootstrap5\Popover;

Popover::begin([
    'title' => 'Hello world',
    'placement' => Popover::PLACEMENT_BOTTOM,
    'toggleButton' => ['label' => 'click me'],
]);

echo 'Say hello...';

Popover::end();

进度条

imgpng

use yii\bootstrap5\Progress;

echo Progress::widget([
    'percent' => 60,
    'label' => '使用率60%'
]);

选项卡

imgpng

use yii\bootstrap5\Tabs;

echo Tabs::widget([
    'items' => [
        [
            'label' => 'One',
            'content' => 'content one...',
            'active' => true
        ],
        [
            'label' => 'Two',
            'content' => 'content two...',
            'headerOptions' => [],
            'options' => ['id' => 'myveryownID'],
        ],
        [
            'label' => 'Example',
            'url' => 'http://www.example.com',
        ],
        [
            'label' => 'Dropdown',
            'items' => [
                 [
                     'label' => 'DropdownA',
                     'content' => 'DropdownA, Anim pariatur cliche...',
                 ],
                 [
                     'label' => 'DropdownB',
                     'content' => 'DropdownB, Anim pariatur cliche...',
                 ],
                 [
                     'label' => 'External Link',
                     'url' => 'http://www.example.com',
                 ],
            ],
        ],
    ],
]);

标签:Yii2,yii,部件,label,options,bootstrap5,btn,class
From: https://www.cnblogs.com/hu308830232/p/18124331

相关文章

  • 人形机器人灵巧手的核心部件 —— 直流永磁伺服电动机
    相关:https://baijiahao.baidu.com/s?id=1770834878767236111&wfr=spider&for=pchttps://news.sohu.com/a/709452614_121742556https://www.bilibili.com/video/BV1gp4y1G7xg/?vd_source=f1d0f27367a99104c397918f0cf362b7......
  • 前端学习-UI框架学习-Bootstrap5-016-卡片
    菜鸟教程链接简单的卡片<template><divclass="card"><h4class="card-title">标题</h4><imgsrc="../assets/th.jfif"alt="537"class="card-img-top"style="width:50px;......
  • 实景三维在城市部件管理中的应用
    实景三维,这个词汇在近年来逐渐走进了我们的视野,尤其是在城市部件管理领域,它正在发挥着越来越重要的作用。那么,实景三维究竟是什么?它在城市部件管理中又有哪些应用呢?今天,我们就来一起探讨这个话题。首先,让我们来了解一下什么是实景三维。实景三维,顾名思义,就是通过对现实世界进行三......
  • Yii2-国际化
    Yii2-国际化配置文件<?php$params=require__DIR__.'/params.php';$db=require__DIR__.'/db.php';$config=[...'components'=>['i18n'=>['translations'=>......
  • 计算机组成与系统结构-第3章 运算方法和运算部件 上
    文章目录3.1高级语言和机器指令中的运算3.1.1C语言程序中涉及的运算数据的运算3.1.2MIPS指令中涉及的运算3.2基本运算部件3.2.1全加器和加法器全加器(FullAdder,简称FA)串行进位加法器/行波进位加法器(carryrippleadder,CRA)。3.2.2并行进位加法器3.2.3带标志加法器3......
  • 前端学习-UI框架学习-Bootstrap5-015-列表组
    菜鸟教程链接列表组+active激活+disabled禁用要创建列表组,可以在元素上添加.list-group类,在元素上添加.list-group-item类:<template><divclass="containermt-3"><h2>列表组</h2><p>列表组+active激活+disabled禁用</p><......
  • Yii2架构简介
    Yii2架构简介Yii2是一个基于组件的PHP框架,它遵循MVC(Model-View-Controller)架构模式。以下是一个简化的Yii2应用程序的基本架构代码概述,以便你可以更好地理解其组成部分和工作原理。目录结构一个典型的Yii2应用程序的目录结构如下:/├──commands/#命......
  • Yii2-助手类(ArrayHelper)
    Yii2-助手类(ArrayHelper)数组助手类ArrayHelperYii数组助手类提供了额外的静态方法,让你更高效的处理数组。模型转数组$model=Country::findOne(['code'=>'BR']);VarDumper::dump(ArrayHelper::toArray($model));//['code'=>'BR''name'=&g......
  • Yii2-助手类(formatter)
    Yii2-助手类(formatter)示例echo\Yii::$app->formatter->asDatetime(time(),'Y-M-dH:i:s');//2023-05-1212:32:32echo\Yii::$app->formatter->asRelativeTime('1447565922');//2小时前echo\Yii::$app->for......
  • yii2-session
    yii2session开启和关闭Sessions$session=Yii::$app->session;//检查session是否开启if($session->isActive)...//开启session$session->open();//关闭session$session->close();//销毁session中所有已注册的数据$session->destroy();访问Session数据......