使用Yii有一年多时间,主要在公司做相应的模块开发,但不清楚到底需要怎么配置。
今天特意下载了一份全新的代码来学习。
1、下载源码:
http://www.yiiframework.com/download/
我选择的是第二种安装方法下载压缩包:
Install from an Archive File
下面有两个下载链接,一个是basic另一个advanced,我是下载的advanced
2、解压放到站点目录下面

解压出来目录与文件,其中的environments文件夹下面的开发与正式环境的配置文件。这里我本地就选用的dev
3、配置文件
A、进入commonconfig文件夹下面

B、修改bootstrap.php文件内容为:
<?php
Yii::setAlias('common', dirname(__DIR__));
Yii::setAlias('frontend', dirname(dirname(__DIR__)) . '/frontend');
Yii::setAlias('backend', dirname(dirname(__DIR__)) . '/backend');
Yii::setAlias('console', dirname(dirname(__DIR__)) . '/console');
Yii::setAlias('static', dirname(dirname(__DIR__)) . '/static');C、修改main.php文件,主要是配置静态文件地址assets
dirname(dirname(__DIR__)) . '/vendor', 'components' => [ 'cache' => [ 'class' => 'yiicachingFileCache', ], 'assetManager' => [ 'basePath' => '@static/assets',//physicalPath 'baseUrl'=>'/static/assets',//virtualPath 'bundles' => [ // you can override AssetBundle configs here ], //'linkAssets' => true, // ... ], 'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, 'suffix' => '.html', // 'rules' => [ // //标准的控制器/方法显示 // '//'=>'/' // ] ],//url的配置 ], ];
D、配置main-local.php主要配置数据库请用与validation
[
'db' => [
'class' => 'yiidbConnection',
'dsn' => 'mysql:host=localhost;dbname=dev',
'username' => 'root',
'password' => '123456',
'charset' => 'utf8',
],
'mailer' => [
'class' => 'yiiswiftmailerMailer',
'viewPath' => '@common/mail',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => true,
],
'request' => [
'enableCookieValidation' => true,
'enableCsrfValidation' => true,
'cookieValidationKey' => 'xxxxxxxxxx',
],
],
];
if (!YII_ENV_TEST) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [
'class' => 'yiidebugModule',
];
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class' => 'yiigiiModule',
];
}
return $config;4、配置前端模块代码
A、frontend/assets/AppAssets.php配置,结合前面common下的配置
<?php
namespace frontendassets;
use yiiwebAssetBundle;
/**
* Main frontend application asset bundle.
*/
class AppAsset extends AssetBundle
{
public $basePath = '@static/frontend/';
public $baseUrl = '/static/frontend/';
public $css = [
'css/site.css',
];
public $js = [
];
public $depends = [
'yiiwebYiiAsset',
'yiibootstrapBootstrapAsset',
];
}B、frontend/config目录下的文件配置,清空除main.php已外文件的内容。
C、删除frontend目录下的web目录
5、设置站点首页及伪静态
index.php
run();
.htaccess
Options +FollowSymLinks
IndexIgnore /
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php第一步配置就至此。已经可正常打开站点了。