YII2 related learning Records, initializing YII2 (ii), initializing yii2_php tutorials

Source: Internet
Author: User
Tags response code email account yii

YII2 related learning Records, initializing YII2 (ii), initializing YII2


The YII2 has been downloaded in the front, so we need to be able to use the actual.

First, initialize, because I am in the Windows system, so with the cmd command to open the downloaded Yii2 root directory. Then run the following command:

Init

You are prompted to select 0 for the development environment and 1 for the build environment. General selection of production environment. Later, you can also enter this command to switch the development environment and production, but pay attention to the need to advance in the "Environments" directory in the pre-written production environment configuration, so as not to overwrite the lost configuration when switching, and then say, now continue to go down.

Second, the configuration database, now the foreground access address is: http://localhost/vishun/backend/web/index.php, the background access address is: http://localhost/vishun/frontend/web/ index.php, where Vishun is the directory name of my YII framework installation. Now the database connection error is reported on the access, because the database is not connected, so we need to create a database first (personal prefer to use phpmyadmin), and then configure the database parameters in Yii2:

Configuration files exist in three places, common/config,frontend/config,backend/config, generally speaking common is used in the front and back of the configuration files, and frontend and backend are put their own configuration files, If repeated, the front and rear tables will be overwritten by the public.

Each folder is divided into main.php and main-local.php, which is mainly for team collaboration, the general team members in their own computer environment developed, and then submitted to Git or SVN. So team members with their own database account password or something, if submitted, other team members update and their account password is incorrect, it will produce errors, so the database and other configuration files in the *-local file, submitted when the *-local file is not submitted.

However, if you do not commit or there will be problems, such as a new member to download the code directly from Git, but the database configuration file because everyone is not committed, the entire program is incomplete, which will lead to the new members have no database configuration. So we need to use the above mentioned environments directory, which has the dev (development) and PROD (production) environment, mainly is the template to store *-local files. When using the init command, the *-local file is generated based on the files in it, and the new member fills in the file with its own database account password to be used.

Detailed description of the above team environment can be seen here: in-depth understanding of the yii2.0--environment and configuration files, said very detailed.

Third, the configuration can be completed, or will error, but not to report the error of the data link, but the user table was not found. Then we'll create the user table. The user table in the YII2 Premium framework is already written, and you can open the *_init.php file under Console/migrations, which is the user table that is written. Simply run the command in the Yii2 root directory in cmd:

Yii Migrate

So the user table is created. At this time access to the front and back of the station are OK. The Migrate command is a tool for the YII framework to migrate or modify the database, especially in team collaboration, if the member adds a table to the local computer, how to inform the other members, the Yii migrate/create command can be used in the console/ Migrations Create a change, and then on the added table content in the inside, after the submission of other members after the update, with the Yii migrate command, you can synchronize their own database to the latest, is absolutely very convenient. Migrate function also many, oneself also did not completely figure out, may in the following front and back separate chapter also will say.

Four, by the way configure the mailbox bar. The first three steps to complete the function, you can register a member to see, when the forgotten password, then click on the login screen forgot password, need to retrieve by mail, so we need to configure the next mailbox:

The YII2 advanced version of the framework is integrated with the mailbox class, which can be seen in the common/config/main-local.php file:

' Mailer ' = [    ' class ' = ' Yii\swiftmailer\mailer ',    ' viewPath ' = ' @common/mail ',] ,

This is the relevant configuration file, which is put into the *-local file because it contains sensitive information about your personal account.

The above configuration information is not complete, need to fill out the sender mailbox, port number and so on, so modify the above for:

' Mailer ' = [    ' class ' = ' Yii\swiftmailer\mailer ',    ' viewPath ' = ' @common/mail ',    / /  Send all mails to a file by default. You has to set    //' Usefiletransport ' to false and configure a transport    ///For the mailer to send real emails.< /c9>    false,    ' transport ' = [          ' class ' = ' Swift_smtptransport ',          //         ' username ' = ' Your mailbox name ',          ' password ' = ' Your email password ', '          port ' = ' ',          ' encryption ' = ' TLS ',    ],
  //'messageConfig'=>[     //  'charset'=>'UTF-8',     //  'from'=>['你的邮箱名'=>'robot'] //],            ],        

The entire process of sending mail is written in the YII2 Premium version, so only the configuration can be sent.

After the configuration is over, you may be able to retrieve the password to send the message should also be an error, similar to this:

Expected response code, but got code "553", with the message "553 Mail from must equal authorized user

This is because some mail servers require that the From and username must have been, for example, NetEase's server, while in frontend/models/passwordresetrequestform.php the SendEmail method prescribes around 63 rows,

->setfrom ([\yii::$app->params[' supportemail '] = \yii::$app->name. ' Robot '])

The from is obtained supportemail parameter, this parameter defines in common/config/params.php the default is: Admin@example.com, the mailbox name in the configuration file and this does not meet so error. Method one is to change this parameter to ' your mailbox name ' can be sent normally, method two is the above configuration file messageConfig comment cancellation, and then->setfrom this line deleted. (All of these first ensure that the SMTP service is first opened)

By the way, because your mailbox configuration is really *-local file, so for other members can also use your this configuration, should be added in environments/dev/common/main-local.php:

' Mailer ' = [    ' class ' = ' Yii\swiftmailer\mailer ',    ' viewPath ' = ' @common/mail ',    / /  Send all mails to a file by default. You has to set    //' Usefiletransport ' to false and configure a transport    ///For the mailer to send real emails.    false,    ' transport ' = [          ' class ' = ' Swift_smtptransport ',          //  Empty, let others fill out their own ' username ' and ' ', ' password ' and ' ', ' "          port ' = ',          ' Encryption ' + ' TLS ',    ],    ' messageconfig ' =[      ' charset ' = ' UTF-8 ',      ' from ' =>[' + ' robot '],                   ],        

In this way, other people just need to fill in their email account to send mail.

Many times the mail is filled out from the database, this time should not be in the configuration file, but should be written in separate classes, (similar to the new components file and introduced, write in here), by the way to encapsulate the delivery method. I have not interned myself, just a train of thought.

The above is the YII2 advanced version of the initialization, the next section may record how to apply a good looking background interface and the GII custom template what. Sleep first.

http://www.bkjia.com/PHPjc/1114011.html www.bkjia.com true http://www.bkjia.com/PHPjc/1114011.html techarticle Yii2 The relevant learning record, initialize YII2 (ii), the initialization yii2 before the YII2 has been downloaded, then we need to be able to use the actual. First, initialize, because I am in ...

  • 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.