Yii2.x's web Configuration

Source: Internet
Author: User
Tags system log yii

I am here on the basis of the basic version of the explanation. But the premium version should be the same. The basic version of the configuration file config/web.php.

Yii default controller is site, here to change to our custom index, only need to $config this array inside add

<?php$config=[... ' Defaultroute ' = ' index ', ...]

You can also change to the default controller you want.

URL beautification

 $config =[    ......          ' defaultroute '  =>  ' index ',         ' Components '  => [         ' Urlmanager '  => [              ' Enableprettyurl '  => true ,             ' Showscriptname '  =>  false,             ' enableStrictParsing '  =>  false,             ' rules '  => [] ,             ' suffix '  =>  '. html ', &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;],&NBSP;&NBSP;&NBSP;&NBSP;]&NBSP;&NBSP;&NBSP;&NBSP, ...] 

Enableprettyurl property: Is required because it can toggle the Nice URL format.

Showscriptname property: Whether to display the entry script name in the constructed URL. The default is true. This property is used only when $ enableprettyurl is true. Creates a url,index.php/user/100 when true. To False when creating a url,/user/100

Enablestrictparsing: This property determines whether strict request resolution is enabled. If strict parsing is enabled, the URL of the incoming request must match at least one rule to be considered a valid request, otherwise a yii \ web \ notfoundhttpexception will be thrown. If strict parsing is disabled, the path information portion of the URL is treated as the requested route when no rules match the requested URL.

Rule: This property contains a list of rules that specify how URLs are resolved and created. The primary property that you should use is to create a URL that is formatted to meet the requirements of a particular application.

The URL suffix to use when Suffix:enableprettyurl is true. For example, you can use ". html" so that the URL looks like a pointer to a static HTML page. This property is used only when $ enableprettyurl is true.

This is the general URL beautification configuration. In is the nginx is added on rewrite

Location/{try_files $uri $uri//index.php? $args;}

Log configuration

$config =[    ......         ' DefaultRoute '  = >  ' index ',         ' components '  => [          ' Urlmanager '  => [              ' Enableprettyurl '  => true,              ' Showscriptname '  => false,              ' enablestrictparsing '  => false,              ' Rules '  => [],              ' suffix '  =>  '. html ',         ],         ' log '  => [          ' TracelEvel '  => YII_DEBUG ? 3 : 0,         ' Targets '  => [            [                  ' class '  =>   ' Yii\log\filetarget ',                  ' Levels '  => [' ERROR ',  ' warning '],                  ' logvars '  => [' _get ',  ' _post '],                  ' LogFile '  =>  "@runtime/logs/". Date ("y-m-d"). ". Log "            ],         ],    ],    ]    ......] 

Yii There are several ways to save a log

    • Yii\log\dbtarget: Store log messages in the database table.

    • Yii\log\emailtarget: Sends a log message to a pre-specified email address.

    • Yii\log\filetarget: Saves the log messages to the file.

    • Yii\log\syslogtarget: syslog() Save the log message to the system log by calling the PHP function.

I'm just talking about myself. The most commonly used save log messages to a file. The rest of the time, in a special blog.

TraceLevel:Set theYii\log\dispatcher::tracelevelthe hierarchy, ifYII_DEBUGThe opening is 3, otherwise it is 0. This means that, ifYII_DEBUGon, each log message is appended with a maximum of 3 call stack levels when log messages are logged;YII_DEBUGclosed, then no call stack information is included.

Class: Explains which method you choose to apply the log to. I am here to save with the file.

Levels: Specifies which message's severity and classification target should be handled.

Logvars: Default contains$_GET$_POST$_FILES$_COOKIE,$_SESSIONand the$_SERVERThese global context requests. What I'm configuring here is the context that records only get and post requests,you can putlogVarsconfigured as an empty array to completely prohibit contextual information from being contained, only the information defined in the levels is recorded in the log.

LogFile: The path and file name of the log. The default is App.log. I configure this to generate logs on a daily basis. (2017-09-01.log)

Write so much first. Have time to share with you later

This article is from the "coding" blog, make sure to keep this source http://xtceetg.blog.51cto.com/5086648/1961860

Yii2.x's web Configuration

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.