lynicidn/yii2-app

lynicidn 的 Yii 2 高级应用模板

安装: 8

依赖: 0

建议者: 0

安全: 0

类型:项目

dev-master 2014-06-23 22:14 UTC

This package is not auto-updated.

Last update: 2024-09-24 08:12:10 UTC


README

Yii 2 高级应用模板是一个最佳用于开发具有多个层的复杂Web应用的骨架Yii 2应用。

模板包括三个层:前端、后端和命令行,每个都是单独的Yii应用。

模板设计用于团队开发环境。它支持在不同的环境中部署应用。

目录结构

common
	config/				contains shared configurations
	mail/				contains view files for e-mails
	models/				contains model classes used in both backend and frontend
	tests/				contains various tests for objects that are common among applications
console
	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
	tests/				contains various tests for the console application
backend
	assets/				contains application assets such as JavaScript and CSS
	config/				contains backend configurations
	controllers/		contains Web controller classes
	models/				contains backend-specific model classes
	runtime/			contains files generated during runtime
	tests/				contains various tests for the backend application
	views/				contains view files for the Web application
	web/				contains the entry script and Web resources
frontend
	assets/				contains application assets such as JavaScript and CSS
	config/				contains frontend configurations
	controllers/		contains Web controller classes
	models/				contains frontend-specific model classes
	runtime/			contains files generated during runtime
	tests/				contains various tests for the frontend application
	views/				contains view files for the Web application
	web/				contains the entry script and Web resources
vendor/					contains dependent 3rd-party packages
environments/			contains environment-based overrides

需求

该应用模板对Web服务器的最低要求是支持PHP 5.4.0。

安装

从存档文件安装

将从 yiiframework.com 下载的存档文件解压到Web根目录下的名为 advanced 的目录中。

然后按照“入门”部分给出的说明操作。

通过Composer安装

如果您没有 Composer,可以按照 getcomposer.org 上的说明进行安装。

您可以使用以下命令安装应用

php composer.phar create-project --prefer-dist --stability=dev yiisoft/yii2-app-advanced advanced

入门

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

  1. 运行 init 命令以使用特定环境初始化应用。
  2. 创建一个新的数据库,并相应地调整 common/config/main-local.php 中的 components['db'] 配置。
  3. 使用控制台命令 yii migrate 应用迁移。这将创建应用工作所需的表。
  4. 设置Web服务器的文档根目录
  • 对于前端 /path/to/yii-application/frontend/web/ 并使用URL http://frontend/
  • 对于后端 /path/to/yii-application/backend/web/ 并使用URL http://backend/

要登录应用,您需要先注册,可以使用任何电子邮件地址、用户名和密码。然后,您可以使用相同的电子邮件地址和密码随时登录应用。

测试

安装额外的Composer包

  • php composer.phar require --dev "codeception/codeception: 1.8.*@dev" "codeception/specify: *" "codeception/verify: *" "yiisoft/yii2-faker: *"

此应用骨架在测试中使用数据库,因此您应该创建三个用于测试的数据库

  • yii2_advanced_unit - 单元测试数据库;
  • yii2_advanced_functional - 功能测试数据库;
  • yii2_advanced_acceptance - 接受测试数据库。

要使数据库保持最新,您可以在所需测试文件夹中运行 yii migrate,例如,如果您从 frontend 测试开始,那么您应该在每个套件文件夹 acceptancefunctionalunit 中运行 yii migrate,这将根据迁移将数据库升级到最后状态。

要能够运行验收测试,您需要一个正在运行的web服务器。为此,您可以使用PHP内置服务器,并在主项目文件夹所在的目录中运行它。例如,如果您的应用程序位于/www/advanced,您只需执行以下操作:cd /www然后php -S 127.0.0.1:8080,因为验收测试的默认配置期望应用程序的URL为/advanced/。如果您已经配置了服务器或应用程序不在名为advanced的文件夹中,您可能需要调整frontend/tests/_bootstrap.phpbackend/tests/_bootstrap.php中的TEST_ENTRY_URL

完成这些后,您应该能够运行您的测试,例如,要运行frontend测试,请

  • cd frontend
  • ../vendor/bin/codecept build
  • ../vendor/bin/codecept run

以类似的方式,您也可以运行其他应用程序层的测试,例如backendconsolecommon

您还可以调整应用程序套件的配置和_bootstrap.php设置以使用其他URL和文件,就像在yii2-basic中那样。当前模板还包括yii2-faker扩展,该扩展已为每个应用程序层正确设置。