Gii is an artifact in yii2. Using it can save a lot of development time.
Now use it to build a user management interface.
The route of Gii is gii, so enter index.php?r=gii to enter the Gii homepage, as follows
The basic crud interface uses Model Generator It can be completed with CRUD Generator.
Because User is the built-in Model of Yii, we no longer need to generate it, but we can take a look at the Model Generator interface
Just enter the table name, Other fields will be filled in automatically. After clicking Next, you can preview the generated file, and then click Generate to automatically generate it.
CRUD Generator can help us generate the V (View) and C (Controller) parts in MVC. The interface is as follows
Add menu statements to \backend\views\layouts\left.php
['label' => 'Manage Users', 'icon' => 'fa fa-users', 'url' => ['user/index'], 'visible' => Yii::$app->user->can('managerUser')],The icon uses fonts awesome(http://fontawesome.io/) The font icons have the same function as Glyphicons in bootstrap, but have more icons.
url is the route to be pointed to.
Visible is whether to display or not. The judgment is based on the previous permissions in rbac. The permissions are used to display the page.
Modify the configuration of the GridView control in \backend\views\user\index.php as follows,
<?= GridView::widget([ 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [ ['class' => 'yii\grid\SerialColumn'], 'username', 'email:email', [ 'attribute' => 'status', 'value' => 'statusLabel', ], 'created_at:datetime', 'updated_at:datetime', [ 'label' => 'Role', 'value' => function($model) { $auth = \Yii::$app->authManager; $roles = $auth->getRolesByUser($model->id); $ret = ''; foreach ($roles as $role) { $ret .= ' ' . $role->name; } return $ret; }, ], ['class' => 'yii\grid\ActionColumn'], ], ]); ?>where email:email is a conventional format of girdview, and the complete one is attribute:format :label, the last two parts of which do not need to be provided.
For the types supported by the second format, you can view the methods starting with as in \yii\i18n\Formatter. For example, email calls the asEmail method of Formatter.
[ 'attribute' => 'status', 'value' => 'statusLabel', ],This is used for customized display, display/sorting of attribute user gridview header, etc. Value is the specific displayed content. In this example, the model (common\models\User) is called. The getStatusLabel method in will display the return value. value can also use anonymous methods, such as the
getStatusLabel method used in the Role field is as follows
/** * @return array */ public static function getStatusList() { return [ self::STATUS_DELETED => 'Deleted', self::STATUS_ACTIVE => 'Active', ]; } /** * @return string */ public function getStatusLabel() { return self::getStatusList()[$this->status]; }The modified display effect is as follows

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Notepad++7.3.1
Easy-to-use and free code editor

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.