Yii2新建项目

kyle 2016-11-09 1388次浏览 0条评论 0 打赏作者 0 0

此处以【掘信博客】blog为例


step 1: 复制添加环境目录
cp -a environments/dev/frontend environments/dev/blog
cp -a environments/prod/frontend environments/prod/blog


step 2:修改添加环境应用配置(vi / vim)
vi environments/index.php
# file: environments/index.php

<?php
// 这里仅说明了我添加了哪些信息,不需要删除任何信息,只需要添加。
return [
    'Development' => [
        'setWritable' => [
            // ... 在原来的后面添加上
            'blog/runtime',
            'blog/web/assets'
        ],
        'setCookieValidationKey' => [
            // ... 在原来的后面添加上
            'blog/config/main-local.php',
        ],
    ],
    'Production' => [
        // 这里和上面一样的添加
    ],
];


step 3:创建应用目录及文件
mkdir -p blog/{assets,config,controllers,models,runtime,web/assets}
touch blog/{assets,config,controllers,models,runtime,web/assets}/.gitkeep


step 4:复制配置文件
cp -a frontend/config/params.php frontend/config/main.php frontend/config/bootstrap.php frontend/config/.gitignore blog/config
cp frontend/runtime/.gitignore blog/runtime/
cp frontend/web/.gitignore blog/web



step 5:修改配置文件(可根据自己需求配置)
vi blog/config/main.php
# file blog/config/main.php

return [
    'id' => 'app-blog',
    // ...
    'controllerNamespace' => 'blog\controllers',
]


step 6:添加公共引导程序
vi common/config/bootstrap.php
# file common/config/bootstrap.php
Yii::setAlias(‘blog’, dirname(dirname(__DIR__)) . ‘/blog’);
// 配置的其它信息看自己的需求而定


step 7:初始化(特别注意:根据提示选择Yes / No 千万小心别把旧项目的配置项给覆盖了)
./init


step 8:新建一个Controller来测试一下
vi blog/controllers/SiteController.php
# file: blog/controllers/SiteController.php

<?php
namespace blog\controllers;
use yii\web\Controller;
class SiteController extends Controller {
    public $layout = false;
    public function actionIndex(){
        return "test";
    }
}


step 9:通过浏览器访问
http://hostname/blog/web/index.php?r=site/index

将域名目录直接指向 你自己项目基础目录/blog/web; 然后通过浏览器访问 http://hostname 看到test字样说明配置成功。

0

0 条评论

    没有找到数据。

发表评论

kyle
土豪

kyle

注册时间:2016-10-28
最后登录:1个月前
发布
带到手机上看