Yii2 initial experience and yii2 initial experience

Source: Internet
Author: User

Yii2 initial experience and yii2 initial experience

 

Yii1.1 was so uncomfortable, and yii2's maturity grew up day by day, so we made up a prototype phase of a small project and tried to use yii2.

With a hand-written experience, let's put it simply from the perspective of Yii1's skilled workers looking at Yii2. (It may be added after this article at any time in the future)

  • The default template uses bootstrap, which is beautiful.
  • The basic and advanced versions of the config file are not the same. In basic, there is web. php, and the latter does not.
  • Set to Chinese display: In config/web. php, add a line 'language '=> 'zh-cn '. Then the Home is changedHomepage, Powered by Yii Framework becomesTechnical support Yii framework.
  • When gii is used to generate a model, I checked Use Table Prefix. The generated model returns {% menu} in the tableName () function }}. If this option is not selected, the full name of the table name is returned, for example, ssn_menu.
  • Many functions are added to models/user. php, which is much more convenient.
  • [...] Is used everywhere in models and controllers to replace array.
  • What is the URL of LibCrudController? R = lib-crud
  • Start to customize the user login part .. Http://www.yiichina.com/tutorial/332
  • Start CRUD (from 20: 20)
  • User: find ()-> all () instead of User: model ()-> findAll ()
  • To reference a User in _ form. php, you must first declare the use app \ models \ User;
  • To reference ArrayHelper in a View File, you must first declare use yii \ helpers \ ArrayHelper;
  • In Yii v1.1, three rows are required for data entry. Here, only one row is required:
<? = $ Form-> field ($ model, 'name1')-> textInput (['maxlength' => true])?>
  • The CRUD interface generated by gii is much more atmospheric and beautiful, and the prompt information is automatically Chinese (this should be the credit of GridView)
  • User: findOne ($ user_id); is different from the following. This returns a record, and the following is unknown.
$ User = User: find ()-> where (['id' => $ id]);
  • Add my.css: First add my.css to web/CSS, and then add it to assets/AppAsset. php.
Public $ css = ['css/site.css ', 'Css/my.css ',];
  • Place the js file: $ this-> registerJsFile ("js/start. js"); -- When jquery is dependent, this is obviously unavailable and the system prompts that $ is not found.
  • Https://segmentfault.com/a/1190000003742452 is very clear here. Several solutions. The modified assets/AppAsset. php solution has been called. One of the key points is (see the black text): AppAsset: addScript ($ this ,'@ Web/Js/start. js ');
  • There is a cool debug-toolbar button in the lower right of the page. A horizontal status bar will pop up when you click it.
  • Index. php in the address bar? R = site/index will change to index. php? R = site % 2 Findex

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.