Yii2.0 新建项目通用准备工作

1.设置 cookieValidationKey 

  在 config/web.php 中 config 里有 components项中request有个cookieValidationKey需要配置参数,可以填写上和项目相关的一个值。

2.Url 路由美化

  初始访问方式为 project/web/index.php?=site/index

  1)【省略掉 ?= 】将 config/web.php 中 config 中components项中 urlManager 整个注释取消,即以下代码,启用框架自带的 路由管理 功能。

1 'urlManager' => [
2             'enablePrettyUrl' => true,
3             'showScriptName' => false,
4             'rules' => [
5             ],
6         ],

  2)【省略掉 index.php】将 包含以下内容的 .htaccess 文件添加到 web 文件夹下。

1 RewriteEngine on
2 # If a directory or a file exists, use it directly
3 RewriteCond %{REQUEST_FILENAME} !-f
4 RewriteCond %{REQUEST_FILENAME} !-d
5 # Otherwise forward it to index.php
6 RewriteRule . index.php

3.配置数据库

  在config/db.php中填写项目用到的数据库相关的dsn、username、password等信息。

4.修改时区

  在onfig/web.php 中 config里添加 timeZone配置项,其值为 'Asia/Shanghai'。如下:

'timeZone' => 'Asia/Shanghai',

 

posted @ 2017-09-20 18:04  teaaa  阅读(151)  评论(0编辑  收藏  举报