且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用新的目录结构创建一个新的 Symfony 项目?

更新时间:2023-11-30 14:21:34

仍然可以触发问题,并将项目转换为新的目录结构.(但前提是您正在创建一个新项目,即运行 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.