delagics/yii2-app-another

Yii 2 另一个项目模板

安装: 187

依赖: 0

建议者: 0

安全: 0

星标: 10

关注者: 7

分支: 4

开放问题: 1

类型:项目

1.0.5 2016-09-19 12:59 UTC

This package is not auto-updated.

Last update: 2024-09-23 07:17:44 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version Code Climate License Yii2

Yii 2 另一个项目模板是一个骨骼Yii 2应用程序,非常适合开发具有多个层级的复杂Web应用程序。

该模板包括三个层级:前端、后端和控制台,每个都是一个独立的Yii应用程序。

该模板旨在在团队开发环境中工作。它支持在不同环境中部署应用程序。

包含内容

注意:目前不包括测试。

要求

该项目模板的最低要求是您的Web服务器支持PHP 5.4.0。推荐使用PHP 7。

安装

使用composer安装

如果您没有Composer,请按照官方指南中的安装Yii部分的说明进行安装。

安装Composer后,您可以使用以下命令安装应用程序

composer global require "fxp/composer-asset-plugin:~1.2"
composer create-project --prefer-dist delagics/yii2-app-another another.dev

第一个命令安装composer asset plugin,该插件允许通过Composer管理bower和npm包依赖项。您只需要运行此命令一次。第二个命令将another应用程序安装在名为another.dev的目录中。如果您想使用不同的目录名,可以选择。

然后按照准备应用程序部分的说明操作。

使用git安装

将仓库作为Web根目录克隆。

git clone git@github.com:delagics/yii2-app-another.git another.dev

名为another.dev的目录是您的Web根目录。

然后安装composer asset plugin,在控制台终端中转到Web根目录,并运行composer install

composer global require "fxp/composer-asset-plugin:~1.2"

cd /var/www/another.dev
composer install

然后按照准备应用程序部分的说明操作。

准备应用程序

安装应用程序后,您需要执行以下步骤来初始化已安装的应用程序。您只需要执行一次。

  1. 创建一个新的数据库。

  2. 在项目根目录中打开控制台终端,并执行php yii init/environment && php yii init/initialize命令,并按照脚本的步骤进行。

当切换到生产环境时,执行php yii init/env并选择PROD环境。

php yii init/env
  1. 设置您的Web服务器的文档根目录

    • 对于 /path/to/another.dev/public/ 并使用 URL http://another.dev/

    对于 nginx,可能是以下内容

    server {
        listen 80;
        charset utf-8;
        client_max_body_size 128M;
        root /var/www/another.dev/public;
        server_name another.dev www.another.dev;
        index index.php index.html index.htm;
        # access_log /var/www/another.dev/logs/access_log.txt;
        # error_log /var/www/another.dev/logs/error_log.txt error;
        location / {
            try_files $uri $uri/ /index.php?$args;
        }
        location /admin {
            try_files $uri $uri/ /admin/index.php?$args;
        }
        location ~ \.php$ {
            #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
            try_files $uri =404;
            include fastcgi_params;
            fastcgi_index index.php;
            fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }
        location /storage {
            # Deny access to any files with a .php extension in the storage directory
            location ~ \.php$ {
                deny all;
            }
            location ~* ^/.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
                expires max;
                add_header Cache-Control public;
                log_not_found off;
                access_log off;
            }
        }
        # Deny all attempts to access hidden files and folders such as .git, .htaccess, .htpasswd, .DS_Store.
        location ~ /\. {
            deny all;
        }
        location = /favicon.ico {
            log_not_found off;
            access_log off;
        }
        location = /robots.txt {
            allow all;
            log_not_found off;
            access_log off;
        }
    }
  1. 更改 hosts 文件,以便将域名指向您的服务器。

    • Windows: c:\Windows\System32\Drivers\etc\hosts
    • Linux: /etc/hosts

    添加以下行

    127.0.0.1   another.dev
    

要登录到应用程序,请使用在运行 php yii init/up 命令时创建的用户名和密码,或使用新凭据注册。

生成应用程序翻译

# For frontend:
php yii message app/front/messages/config.php

# For backend:
php yii message app/back/messages/config.php

目录结构

app/
    base/                    contains classes shared between all apps
        config/              contains shared configurations
        mail/                contains view files for e-mails
        models/              contains model classes used in both backend and frontend apps
    console/                 contains classes for the console app
        config/              contains console configurations
        controllers/         contains console controllers (commands)
        migrations/          contains database migrations
        models/              contains console-specific model classes
        runtime/             contains files generated during runtime
    back/                    contains classes for the backend app
        assets/              contains backend app assets
        config/              contains backend configurations
        controllers/         contains backend Web controller classes
        models/              contains backend-specific model classes
        runtime/             contains files generated during backend app runtime
        views/               contains view files for the backend Web app
    front/                   contains classes for the frontend app
        assets/              contains frontend app assets
        config/              contains frontend configurations
        controllers/         contains frontend Web controller classes
        models/              contains frontend-specific model classes
        runtime/             contains files generated during frontend app runtime
        views/               contains view files for the frontend Web app
        widgets/             contains frontend widgets
    vendor/                  contains dependent 3rd-party packages
public/                      contains the entry script and Web resources for the frontend app
    storage/                 contains files such as user uploaded images, docs, archives shared between all appliactions
    admin/                   contains the entry script and Web resources for the backend app
        assets/              contains Web resources published by AssetBundles of backend app
        index.php            contains the entry script of the backend app
    assets/                  contains Web resources published by AssetBundles of the frontend app
    index.php                contains the entry script of the frontend app
.env.example                 contains template for a dotenv file.

由 @delagics 制作,满满的爱❤️