缺少 Symfony2 捆绑资源文件


Symfony2 Bundles resource file missing

我在Symfony2项目中安装了许多捆绑包(我使用Symfony 2.8)。我按照文档与作曲家一起安装这些捆绑包。但是当我尝试访问页面时,许多资源文件丢失(错误 404)。

例如,使用捆绑包TinymceBundle。

web/js/tinymce/tinymce.min.js

不见了。

捆绑包实际上可以工作,但缺少此文件。

这是我的作曲家.json :

{
    "name": "symfony/framework-standard-edition",
    "license": "MIT",
    "type": "project",
    "description": "The '"Symfony Standard Edition'" distribution",
    "autoload": {
        "psr-0": { "": "src/", "SymfonyStandard": "app/" }
    },
    "require": {
        "php": ">=5.3.3",
        "symfony/symfony": "2.8.*",
        "codeplex/phpexcel": "dev-master",
        "doctrine/orm": "~2.2,>=2.2.3,<2.5",
        "doctrine/dbal": "<2.5",
        "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": "~3.0,>=3.0.12",
        "sensio/framework-extra-bundle": "~3.0,>=3.0.2",
        "incenteev/composer-parameter-handler": "~2.0",
        "knplabs/knp-menu": "2.1.1",
        "knplabs/knp-menu-bundle": "2.1.1",
        "genemu/form-bundle": "2.2.*",
        "swiftmailer/swiftmailer": "@stable",
        "gregwar/captcha-bundle": "1.0.12",
        "knplabs/knp-snappy-bundle": "dev-master",
        "egulias/email-validator": "~1.2",
        "friendsofsymfony/jsrouting-bundle": "^1.5",
        "doctrine/doctrine-fixtures-bundle": "~2.2",
        "stfalcon/tinymce-bundle": "1.0"
    },
    "require-dev": {
        "sensio/generator-bundle": "~2.3"
    },
    "scripts": {
        "post-root-package-install": [
            "SymfonyStandard''Composer::hookRootPackageInstall"
        ],
        "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",
            "Sensio''Bundle''DistributionBundle''Composer''ScriptHandler::removeSymfonyStandardFiles"
        ],
        "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",
            "Sensio''Bundle''DistributionBundle''Composer''ScriptHandler::removeSymfonyStandardFiles"
        ]
    },
    "config": {
        "bin-dir": "bin",
    },
    "extra": {
        "symfony-app-dir": "app",
        "symfony-web-dir": "web",
        "symfony-assets-install": "relative",
        "incenteev-parameters": {
            "file": "app/config/parameters.yml"
        },
        "branch-alias": {
            "dev-master": "2.6-dev"
        }
    } 
}

我不明白为什么文件不在 web/js 中,你能帮我吗?

编辑:

有我的样式表块

{% block stylesheet %}
    <link rel="stylesheet" href="{{ asset('css/DT_bootstrap.css') }}" />
    <link rel="stylesheet" href="{{ asset('css/datatables.responsive.css') }}" />
    {{ tinymce_init({
        theme: {'simple':{'language': app.request.locale, 'height': 200 }},
        toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image",
        autosave_ask_before_unload: false })
    }}
{% endblock %}

和我的链接脚本块

{% block linkscript %}
    <script type="text/javascript" src="{{ asset('js/dataTable/datatables.responsive.js') }}"></script>
    <script type="text/javascript" src="{{ asset('js/tinymce/tinymce.min.js') }}"></script>
{% endblock %}

谢谢!

如果缺少捆绑资产(它们不是在 assets 文件夹中创建的),则可能不会将这部分代码添加到 AppKernel:

<?php
// ...
public function registerBundles()
{
    $bundles = array(
        // ...
        new Stfalcon'Bundle'TinymceBundle'StfalconTinymceBundle(),
    );
}

实际上我已经下载了Symfony 2.8和stfalcon/tinymce-bundle - 你只需要将代码添加到AppKernel,然后运行

php app/console assets:install web/

然后将这部分添加到树枝模板中:

{{ tinymce_init() }}

之后,应注入所有文件。此函数将使用此路径来包含 tinemce:

web/bundles/stfalcontinymce/vendor/tinymce/tinymce.min.js

综上所述。如果在运行控制台命令后未显示资产文件,则可能是您没有将捆绑包添加到 AppKernel,或者您可能在错误的位置查找此文件。默认情况下,资产将放置在

/web/bundles/*