![](https://img-blog.csdnimg.cn/20201014180756913.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
yii2
文章平均质量分 75
卫沧澜
一个程序猪
展开
-
yii2基础之modal弹窗的基本使用
Modal也即是模态窗,通俗的说就是弹窗。是一款bootstrap的js插件,使用效果也是非常好。为什么要使用modal就不必多说了,一个网站,在开发过程中你说你没用过js弹窗我都不信!好的弹窗不仅仅给人以美感,也会让我们开发效率提高,甚至心情也会舒畅!我们看看在yii2中如何使用modal。比如我们之前添加数据的时候,通常情况下会点击按钮跳转到添加页面,保存后再跳转到列表页。现在转载 2017-04-21 15:31:44 · 2818 阅读 · 0 评论 -
Yii2 自带事件的用法
Model 层保存之前的事件示例public function beforeSave($insert){ if (parent::beforeSave($insert)) { // 插入新数据判断订单号是否存在 if (!Order::findModel(['trade_no' => $this->order_trade_no])) {转载 2017-05-09 10:57:15 · 981 阅读 · 0 评论 -
yii2中controller向layout传值
方式一:1.controllerclass BlogController extends Controller{ public $layout = 'newlayout'; public $menu = ""; public function actionIndex(){ $this->menu = 'menumenu'; retu转载 2017-04-25 17:21:16 · 1073 阅读 · 0 评论 -
Yii2 回到顶部插件
yii2-scroll-topA Yii2 widget to add scroll-to-top button. Base on the .animate jQuery function.Yii2 回到顶部按钮,基于jQuery的animate,支持自定义内容和样式。InstallationThe preferred way to install this extension i转载 2017-04-25 11:47:57 · 364 阅读 · 0 评论 -
修改index页面的搜索
gii生成后,index页面,添加按钮旁边会有搜索按钮,如果需要的话可以根据业务需求修改.现在的业务需求是如图现在修改视图中的index,部分代码如下 'btn btn-success pull-right', 'style' => 'padding:6px 26px']) ?> 'btn btn-info search-button转载 2017-04-25 10:31:27 · 474 阅读 · 0 评论 -
GridView 如何取消排序
searchModel里写操作gii生成index页面,点击字段可排序,现在想取消排序:如何取消排序" title="GridView 如何取消排序" height="228" width="690">$dataProvider = new ActiveDataProvider([ 'query' => $query,]); $dataProvider->setSort(false);转载 2017-04-20 18:16:22 · 2285 阅读 · 0 评论 -
语言包使用
1配置文件.frontend\config\main.php组件里添加'i18n'=>[ 'translations'=>[ '*'=>[ 'class'=>'yii\i18n\PhpMessageSource', //'basePath'=>'/me转载 2017-04-20 18:18:50 · 516 阅读 · 0 评论 -
GridView"操作"部分修改
一.增加/减少操作,如图添加了approve操作,approve为控制器里的actionApprove(),减少同理[ 'class' => 'yii\grid\ActionColumn', 'template' => '{view}{update}{delete}{approve}', 'buttons' => [ 'approve' => f原创 2017-04-21 10:08:51 · 307 阅读 · 0 评论 -
简单实现支持用户名和邮箱登录
一.LoginForm里的login()调了getUser(),所以修改getUser()即可 public function login() { if ($this->validate()) { return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600转载 2017-04-21 10:28:46 · 2109 阅读 · 0 评论 -
attributeHints()
效果实现一.在model里添加public function attributeHints(){ return [ 'name'=>'填写商品名称', ];}二.在视图中添加field($model, 'name')->hint('填写商品名')?>原创 2017-04-21 10:39:36 · 250 阅读 · 0 评论 -
时间格式化统一配置
common/config/main.phpcomponents下配置'formatter' => [ 'dateFormat' => 'yyyy-MM-dd', 'datetimeFormat' => 'yyyy-MM-dd HH:mm:ss', 'decimalSeparator' => '.', 'thousandSeparator' => ' ',转载 2017-04-21 10:43:04 · 366 阅读 · 0 评论 -
LogBehavior
记录用户操作日子<?phpnamespace app\components\behaviors;use app\models\Log;use Yii;use yii\base\Behavior;use yii\base\ErrorException;use yii\bootstrap\Html;use yii\db\ActiveRecord;class LogBehavio原创 2017-04-21 11:33:26 · 345 阅读 · 0 评论 -
umeditor编辑器
效果下载https://packagist.org/packages/shiyang/yii2-umeditor配置<?php echo $form->field($model, 'content')->widget('common\widgets\umeditor\UMeditor', [ 'clientOptions' =>转载 2017-04-21 11:48:29 · 396 阅读 · 0 评论 -
Yii2 最简单的实现管理员才能登录后台
场景有时候一个小项目,想实管理员才能登录后台,其实没必要引入复杂的 RBAC,可以利用 Yii User 表里面的 role 字段来实现这个效果。实战:后台只有管理员才能登录第一步:修改 common\models\User 文件,添加如下静态常量:const ROLE_USER = 10;const ROLE_ADMIN = 20;第二步:修改 common\models转载 2017-05-09 11:18:25 · 4486 阅读 · 0 评论