Symfony 2 网页目录重命名

Symfony 2 web directory rename

我有一个 Symfony 2 项目,但由于某些原因我无法重命名 Web 目录。我正在尝试将其重命名为 public.

根据手册,我想更改 composer.json 并确保 app.php 和 app_dev.php 中的链接正确。

但是当我运行 app/console server:run 时,它显示

 The given document root directory "C:/xampp/htdocs/xxx/app/../web" does nto exists.

我已经更改了 composer.json,运行 composer install 和 composer update 但仍然没有成功。这是我的 composer.json ,如您所见,我已经将 "symfony-web-dir": "public" 添加到文件中。

如果我将我的 public 文件夹重命名为 web,那么一切都很好,但由于某些原因我不能这样做。

{
"name": "symfony/framework-standard-edition",
"license": "MIT",
"type": "project",
"description": "The \"Symfony Standard Edition\" distribution",
"autoload": {
    "psr-0": { "": "src/" }
},
"require": {
    "php": ">=5.3.3",
    "symfony/symfony": "~2.4",
    "doctrine/orm": "~2.2,>=2.2.3",
    "doctrine/doctrine-bundle": "~1.2",
    "twig/extensions": "~1.0",
    "symfony/assetic-bundle": "~2.3",
    "symfony/swiftmailer-bundle": "~2.3",
    "symfony/monolog-bundle": "~2.4",
    "sensio/distribution-bundle": "~2.3",
    "sensio/framework-extra-bundle": "~3.0",
    "sensio/generator-bundle": "~2.3",
    "incenteev/composer-parameter-handler": "~2.0",
    "richsage/rms-push-notifications-bundle": "dev-master",
    "friendsofsymfony/user-bundle": "~1.3",
    "ircmaxell/password-compat": "~1.0.3"
},
"scripts": {
    "post-install-cmd": [
        "Incenteev\ParameterHandler\ScriptHandler::buildParameters",
        "Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap",
        "Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache",
        "Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installAssets",
        "Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installRequirementsFile"
    ],
    "post-update-cmd": [
        "Incenteev\ParameterHandler\ScriptHandler::buildParameters",
        "Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap",
        "Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache",
        "Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installAssets",
        "Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installRequirementsFile"
    ]
},
"config": {
    "bin-dir": "bin"
},
"extra": {
    "symfony-app-dir": "app",
    "symfony-web-dir": "public",
    "incenteev-parameters": {
        "file": "app/config/parameters.yml"
    },
    "branch-alias": {
        "dev-master": "2.4-dev"
    }
}

}

您确实可以更改'web' 目录的名称,但server:run 命令不希望这样。正如您在 ServerRunCommand 源代码 (on line 77) 中看到的那样,'web' 目录是硬编码的。

但是,您应该能够通过在 运行 命令时提供 --docroot 选项来解决此问题:

bin/console server:run --docroot=C:/xampp/htdocs/xxx/public

(将 bin/console 替换为控制台的位置,如果您使用的是 Symfony 2 结构,则可能是 app/console