Seeing that Yii1.1 has so many dissatisfaction, and seeing Yii2 maturing day by day, I put together a prototype stage of a small project and tried to use Yii2.
I wrote down some experience, briefly speaking from the perspective of a Yii1 skilled worker looking at Yii2. (Additions may be added at the end of this article at any time in the future)
- The default template uses bootstrap, which is very beautiful.
- The config files of the basic version and the advanced version are different. In the basic version, there is web.php, but the latter does not.
- Set to display in Chinese: In config/web.php, add a line 'language'=>'zh-CN'. Then Home became Homepage, and Powered by Yii Framework became Technical Support Yii Framework.
- Use gii to generate the model. I checked Use Table Prefix. The tableName() function of the generated model returns {{%menu}}. If not checked, the full name of the table name will be returned, such as ssn_menu
- Many functions have been added to models/user.php, which is much more convenient.
- In models and controllers, use [ ... ] instead of array(...) everywhere, which is much more beautiful and refreshing.
- The corresponding URL of LibCrudController is ?r=lib-crud
- Start trying to customize the user login part. . http://www.yiichina.com/tutorial/332
- Start doing CRUD (from 20:20)
- User::find()->all() instead of User::model()->findAll()
- To reference User in _form.php, you need to declare use appmodelsUser; first
- To reference ArrayHelper in the view file, you must first declare use yiihelpersArrayHelper;
- In Yii v1.1, the data entry element requires three lines, but here it only needs one line:
- The CRUD interface generated by gii is much more elegant and beautiful, and the prompt information is automatically in Chinese (this should be the credit of GridView)
- User::findOne($user_id); is different from the one below. This returns a record, I don’t know what the following is.
- Add my.css: First add my.css in web/css, and then in assets/AppAsset.php
- Insert js file: $this->registerJsFile("js/start.js"); --When relying on jquery, this obviously does not work, and it will prompt that $ cannot be found.
- https://segmentfault.com/a/1190000003742452 It’s very clear here. Several options. The plan to modify assets/AppAsset.php has been adjusted. One of the key points is (see boldface): AppAsset::addScript($this,'@web/js/start.js');
- There is a cool debug-toolbar button on the lower right side of the page. Clicking it will pop up a horizontal status bar.
- index.php?r=site/index in the address bar will become index.php?r=site%2Findex

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

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

WebStorm Mac version
Useful JavaScript development tools

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.

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