使用新的目录结构创建

使用新的目录结构创建

本文介绍了如何使用新的目录结构创建一个新的 Symfony 项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

直到几天前,还可以使用新的 (Symfony 3) 目录结构创建新的 Symfony 项目.当运行 composer create-project symfony/framework-standard-edition path/"2.5.*" 时,Composer 会问以下问题:

Until some days ago, it was possible to create a new Symfony project with the new (Symfony 3) directory structure. When running composer create-project symfony/framework-standard-edition path/ "2.5.*", Composer would ask the following question:

您想使用 Symfony 3 目录结构吗?[是/否]

新结构提供了一些改进,例如 consoleapp 目录移动到 bin 目录,以及 phpunit.xml.distapp 目录移动到根目录.缓存和日志目录已移至新的 var 目录.

The new structure offered some improvements, such as console being moved from the app directory to the bin directory, and phpunit.xml.dist being moved from the app directory to the root directory. The cache and logs directories were moved to a new var directory.

查看这个答案(由我编写)以获取完整的更改列表.

Take a look at this answer (written by me) for a full list of changes.

但是,全新安装的标准发行版不再提供此选项.似乎问题 已于 7 月 16 日删除,因为创建了新的目录结构太多的困惑,尤其是对于新用户.另请参阅 GitHub 上的此问题.

However, a fresh install of the standard distribution no longer offers this option. It seems like the question has been removed on July 16th, because the new directory structure created too much confusion, especially for new users. See this issue on GitHub as well.

是否仍然可以使用新的目录结构创建项目?

Is it still possible to create a project using the new directory structure?

推荐答案

仍然可以触发问题,并将项目转换为新的目录结构.(但前提是您正在创建一个新项目,即运行 composer create-project)

It is still possible to trigger the question, and convert a project to the new directory structure. (but only if you are creating a new project, i.e. running composer create-project)

为此,您需要将 SENSIOLABS_ENABLE_NEW_DIRECTORY_STRUCTURE 环境变量设置为 true.这可以通过在 Composer 命令前添加 SENSIOLABS_ENABLE_NEW_DIRECTORY_STRUCTURE=true 来完成.

To do so, you need to set the SENSIOLABS_ENABLE_NEW_DIRECTORY_STRUCTURE environment variable to true. This can be done by prepending SENSIOLABS_ENABLE_NEW_DIRECTORY_STRUCTURE=true to the Composer command.

因此,为了创建一个新项目,请在终端中运行以下命令:

So in order to create a new project, run the following command in your terminal:

SENSIOLABS_ENABLE_NEW_DIRECTORY_STRUCTURE=true composer create-project symfony/framework-standard-edition path/ "2.5.*"

Composer 会询问您是否需要新的目录结构.

and Composer will ask you if you want the new directory structure.

正如 barius 在评论中所指出的,此功能已从 2.7.5 版的 Symfony 标准版中删除.如果你真的想使用Symfony 3的结构,你可以通过2步安装Symfony来获得:

As noted by barius in the comments, this feature has been removed from the Symfony Standard Edition per version 2.7.5. If you really want to use the Symfony 3 structure, you can get it by installing Symfony in 2 steps:

  1. 创建一个带有版本约束的新 Symfony 项目,以便获得 2.6 版本,它仍会询问您是否要使用新的目录结构.
  2. 然后更改 symfony/symfony 包的版本约束,以便您仍能获得最新版本.
  1. Create a new Symfony project with a version constraint so you get the 2.6 version, which still asks you whether you want to use the new directory structure.
  2. Then change the version constraint for the symfony/symfony package so you'll still get the latest version.

因此,从命令行执行以下命令:

So, execute the following commands from the command line:

SENSIOLABS_ENABLE_NEW_DIRECTORY_STRUCTURE=true composer create-project symfony/framework-standard-edition project-directory/ "2.6.*"
cd project-directory
composer require symfony/symfony ^2.7

注意:我实际上并不推荐这个,因为这不是官方推荐的创建新 Symfony 项目的方式.因此,除非您真的知道自己在做什么,否则只需使用 Symfony 安装程序来创建新项目.

Note: I don't actually recommend this, as this is not the official recommended way to create a new Symfony project. So unless you really know what you're doing, just use the Symfony Installer to create new projects.

这篇关于如何使用新的目录结构创建一个新的 Symfony 项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!