我在Symfony2项目中安装了很多bundle(我使用Symfony 2.8)。我按照doc安装这些捆绑包与composer。但是当我尝试访问页面时,许多资源文件丢失了(错误404)。
例如,使用Bundle TinymceBundle。
网/ JS / TinyMCE的/ tinymce.min.js
缺少。
捆绑包实际上有效,但缺少此文件。
这是我的composer.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 %}
我的 linkscript阻止:
{% 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 %}
谢谢!
答案 0 :(得分:1)
如果缺少捆绑资产(它们不是在资产文件夹中创建的),您可能不会将这部分代码添加到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/
然后添加到twig模板这一部分:
{{ tinymce_init() }}
之后应该注入所有文件。此函数将使用此路径包含tinemce:
web/bundles/stfalcontinymce/vendor/tinymce/tinymce.min.js
总结一下。如果在运行console命令后没有出现assets文件,可能你没有将bundle添加到AppKernel,或者你可能在错误的地方寻找这些文件。默认情况下,资产将放在
中/web/bundles/*