1

我正在使用 symfony 2、composer 和 sass 框架

我在 MYBundle/Resources/public/ 下有名为 files/ 和 images/ 的额外文件夹

出于某种原因,当我运行命令时,此文件或图像文件夹未在 web/ .. 下创建:

php 应用程序/控制台资产:安装

但是他们确实在 web/bundles/mybundle/files..

与图像文件夹相同:web/bundles/mybundle/images..

我只有这些文件夹..在网络下..

web/ 
  bundles/
  css/ 
  js/

如何在 web/ 下获取我的另外两个文件夹,它们是图像和文件文件夹...

像这样..

web/ 

 bundles/ 
 images/ 
 css/ 
 js/ 
 files/

因为我需要在文件/文件夹中保留一些文件,例如termsandconditions.pdf..

我在 config.yml 中的配置是:

# Assetic Configuration

parameters:
    # Assetic
    assetic.filter.compass.images_dir: %kernel.root_dir%/../web/images
    assetic.filter.compass.http_path:  /images
    assetic.filter.compass.images_dir: %kernel.root_dir%/../web/files
    assetic.filter.compass.http_path:  /files

assetic:
    debug:          %kernel.debug%
    use_controller: false
    filters:
        sass:    ~
        compass: ~
        cssrewrite: ~

树枝文件中的路径是:

<div class="small-4 columns">
                <p>I accept the <a href="{{ asset('/files/terms_and_conditions.pdf') }}" target="_blank"><span class="pinkText">Terms and Conditions</span></a></p>
            </div>

如果有人知道步骤,请告诉我...我对 Symfony 很熟悉

4

2 回答 2

0

当您安装资产时,您的公用文件夹中的所有内容都将被复制到 Web 文件夹。

所以创建一个文件夹文件,然后像这样调用它们:

<p>I accept the <a href="{{ asset('bundles/bundleName/files/terms_and_conditions.pdf') }}">

或使用控制器为其提供服务

use Symfony\Component\HttpFoundation\BinaryFileResponse;



Class Controller ....
    function downloadTermsAndCondsAction() {

    $file = __DIR__.'/../../../../web/bundles/bundleName/files/terms_and_conditions.pdf';
    $response = new BinaryFileResponse($file);
    return $response;
}
于 2013-10-21T10:29:30.147 回答
0

在您的具体情况下,我建议您手动将您的 terms_and_conditions.pdf 放入 web/ 文件夹中。没有必要使用 bundle/app/assetic 来解决这种情况,当然也不需要为此使用控制器。

于 2016-01-12T14:27:36.817 回答