delagics / yii2-app-another
Yii 2 另一个项目模板
Requires
- php: >=5.4.0
- codemix/yii2-localeurls: ~1.4
- dektrium/yii2-rbac: dev-master
- dektrium/yii2-user: 0.9.*@dev
- vlucas/phpdotenv: ~2.2
- yiisoft/yii2: ~2.0
- yiisoft/yii2-bootstrap: *
- yiisoft/yii2-swiftmailer: *
Requires (Dev)
This package is not auto-updated.
Last update: 2024-09-23 07:17:44 UTC
README
Yii 2 另一个项目模板是一个骨骼Yii 2应用程序,非常适合开发具有多个层级的复杂Web应用程序。
该模板包括三个层级:前端、后端和控制台,每个都是一个独立的Yii应用程序。
该模板旨在在团队开发环境中工作。它支持在不同环境中部署应用程序。
包含内容
- 改进的项目结构(见目录结构);
- 通过codemix/yii2-localeurls通过URL进行语言管理;
- 灵活的用户注册和认证模块(dektrium/yii2-user);
- RBAC管理模块(dektrium/yii2-rbac);
yii init
控制台命令,简化项目准备;- 支持PHP dotenv,便于项目配置,具有类似Laravel的环境变量获取器:
env('YII_ENV', 'dev')
;
注意:目前不包括测试。
要求
该项目模板的最低要求是您的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
然后按照准备应用程序部分的说明操作。
准备应用程序
安装应用程序后,您需要执行以下步骤来初始化已安装的应用程序。您只需要执行一次。
-
创建一个新的数据库。
-
在项目根目录中打开控制台终端,并执行
php yii init/environment && php yii init/initialize
命令,并按照脚本的步骤进行。
当切换到生产环境时,执行php yii init/env
并选择PROD
环境。
php yii init/env
-
设置您的Web服务器的文档根目录
- 对于
/path/to/another.dev/public/
并使用 URLhttp://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; } }
-
更改 hosts 文件,以便将域名指向您的服务器。
- Windows:
c:\Windows\System32\Drivers\etc\hosts
- Linux:
/etc/hosts
添加以下行
127.0.0.1 another.dev
- Windows:
要登录到应用程序,请使用在运行 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 制作,满满的爱❤️