Yii2的相干学习记录,后台模板和gii(三)
Yii2的相关学习记录,后台模板和gii(三)
前面已经可以正常登录,但我们需要体验下最常用的增删查改的操作。这里就需要gii,通过gii可以方便的生成表单、表格的框架,不需要我们再写重复的东西。
gii访问地址:http://localhost/vishun/frontend/web/index.php?r=gii或者http://localhost/vishun/backend/web/index.php?r=gii,由于前后台文件都有配置,所以都可以访问。由于Yii框架高级版已经在common/models中存在user模型了,所以,我们直接用CRUD来生成user表的后台控制器和增删查改的表单。这没什么好说的,由于是高级版本,所以将提示中的app(基础版是app)改成你想要生成的目录(backend、frontend、common),如下图:
生成后就可以访问查看了:http://localhost/vishun/backend/web/index.php?r=user,如下图:
还是蛮不错的,可以点击看看,比Yii1的界面要好多了。但是单单这种界面,当我有多个表的展示时,是满足不了我们的要求的。所以应该有一个比较好的后台展示模板才行,网上搜了下,挺多人推荐AdminLTE模板,界面也不错,和阿里云的后台有点像,就打算用它了。
这时候我们又会用到原先提到的packagist,在其中搜索“yii2-adminlte”,会看到很多人已经将这个模板与Yii2集成在一起了,这里我们选择下载量最多的“dmstr/yii2-adminlte-asset”来作为我们的模板。一切按照操作说明来即可,需要注意的地方:
1、由于composer默认会下到vendor中,而一些菜单添加配置等文件同样需要我们自己在vendor目录中配置,这显然是不合适的,因为vendor目录在团队合作中是不提交的(vendor文件太大,而且团队成员通过composer.json,可轻松下载更新vendor文件)。所以必须按照说明将文件copy出来。方法一,可以作为一个主题,在backend/config/main.php的配置文件中:如下
'view' =><span style="color: #000000;">[ </span>'theme' =><span style="color: #000000;">[ </span>'pathMap' => [[email protected]/views'=>[email protected]/themes/default'],<span style="color: #008000;">//</span><span style="color: #008000;">在backend中新建themes/default文件文件</span> 'baseUrl' => [email protected]/themes/default',<span style="color: #000000;"> ]</span>,<span style="color: #000000;">]</span>,
方法二:直接覆盖backend/views中的文件,当然上方的配置文件也不需要写了,去掉就行。
2、更改颜色主题时,文档说的不是很明白,除了配置文件外,还需要更改你拷贝文件中的layouts/main.php中下面这行:
class="hold-transition skin-purple sidebar-mini">
改成和配置文件css名一致就可以更改主题颜色了。
现在即便增加其它表的展示,只需要在拷贝文件中的layouts/left.php的menu小部件中增加,就会在左边显示出来,而且整体也比原先好看多了:
这里还有两个延伸要说,一个是如何自定义gii模板,一个是如何引用AdminLTE中的其它扩展css、js等,不过太晚了,先睡觉了。

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

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

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.
