小编Jay*_*ybe的帖子

如何在TinyMCE中编写twig标签

我有一个问题与TinyMce结合Twig,我试图将带有twig标签的html粘贴到tinyMce中.(使用原始html)

这就是我想要的结果:

<table>
<thead>
    <tr>
        <th></th>
        {% for period in report.periods %}
            <th>
                {% set per = "last_" ~ period %}
                {{ per | trans({}, "admin") }}
            </th>
        {% endfor %}
    </tr>
</thead>
<tbody>
    {% for category in report.categories %}
        <tr>
            <td>
                <b>{{ category | trans({}, "admin") }}</b>
            </td>
            {% for period in report.periods %}
                <td>
                    {{ data[category][period] }}
                </td>
            {% endfor %}
        </tr>
    {% endfor %}
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)

这就是我将其粘贴到tinyMce并验证我的HTML时的样子

<p>{% for period in report.periods %} {% endfor %} {% …
Run Code Online (Sandbox Code Playgroud)

tinymce symfony twig

6
推荐指数
3
解决办法
1380
查看次数

BinaryFileResponse:无法在BinaryFileResponse实例上设置内容

我尝试从Controller下载文件(此处为附件)

这是我的代码:

/**
 * @param Request    $request
 * @param Attachment $attachment
 *
 * @Route("/message/{thread_id}/download/{attachment_id}", name="faq_download_attachment")
 * @ParamConverter("attachment", options={"id" = "attachment_id"})
 *
 * @return BinaryFileResponse
 *
 * @throws \Symfony\Component\Filesystem\Exception\FileNotFoundException
 */

public function downloadFiletAction(Request $request, Attachment $attachment)
{
    $mountManager = $this->get('oneup_flysystem.mount_manager');
    $fileSystem = $mountManager->getFilesystem('faq');
    return new BinaryFileResponse($fileSystem->getAdapter()->getPathPrefix() . $attachment->getFilename());
}
Run Code Online (Sandbox Code Playgroud)

这段代码:

$fileSystem->getAdapter()->getPathPrefix() . $attachment->getFilename()
Run Code Online (Sandbox Code Playgroud)

返回绝对路径(这是正确的)

在此输入图像描述 最后,我收到此错误=> 无法在BinaryFileResponse实例上设置内容.

似乎当我实例化BinaryFileResponse时,symfony将它的内容设置为NULL(这就是我想要的)但是当我放入return语句时.我的内容被一个空字符串替换,这是一件坏事,因为BinaryFileResponse的以下函数抛出异常.

public function setContent($content)
{
    if (null !== $content) {
        throw new \LogicException('The content cannot be set on a BinaryFileResponse instance.');
    }
}
Run Code Online (Sandbox Code Playgroud)

此外,如果我删除setContent方法中的if语句,Everything就像一个魅力.(但这不是最好的事情)

谢谢您的帮助

symfony

6
推荐指数
1
解决办法
1702
查看次数

标签 统计

symfony ×2

tinymce ×1

twig ×1