GridField文件链接使用HTML实体重新编写

GridField文件链接使用HTML实体重新编写

本文介绍了SilverStripe 3.1 GridField文件链接使用HTML实体重新编写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Silverstripe(3.1)的新手.我正在使用它来收集用户的应用程序.每个用户都上载一个文件,以后有人可以在CMS中下载该文件.名为文档"的文件具有has_one关系.我想链接到GridField中的该文件.因此,经过一番搜索,我做了下面的解决方案-简单,而且除了一个问题外,它都可以工作.

I'm very new to Silverstripe (3.1). I am using it to collect applications from users. Each user uploads a file which later in the CMS somebody can download.There is a has_one relationship for the file called 'Document.'I want to link to that file inside a GridField. So after some searching I did the solution below - easy, and it works except for one problem.

该链接的确出现在GridField的正确列内,但已通过HTMLSpecialChars()之类的东西进行了转换,我可以看到所有的HTML.为了我的一生,我无法想出如何阻止它.我想知道这种转换发生在哪里?我该如何规避呢?

The link does appear inside the correct column in the GridField but it has been converted through something like HTMLSpecialChars() and I can see all the HTML. For the life me I cannot figure how to stop it.I would like to know where this conversion is taking place?and how can I circumvent it?

$submissionGrid = new GridField('submissions', 'Submissions', $submission, $config );

$submissionGrid->addDataFields(array(
        "Document" => function($row) {
            $link = '<a href="' . $row->Document()->getAbsoluteURL() . '">Download Document</a>';
            return $link;
        },
    ));

推荐答案

您非常接近.

您不是在addFields()上尝试了setFieldFormatting在您的gridfield的配置上吗?

Instead of addDataFields(), have you tried setFieldFormatting on the configuration of your gridfield?

$submissionGrid = new GridField('submissions', 'Submissions', $submission, $config );
$config = $submissionGrid->getConfig();
$config->getComponentByType('GridFieldDataColumns')->setFieldFormatting(array(
    "Document" => function($value, $item) {
        $link = '<a href="' . $item->Document()->getAbsoluteURL() . '">Download Document</a>';
        return $link;
    },
));

根据提交数据对象"上可用的字段,如果要添加文档"作为自定义列到网格字段,则还需要使用setDisplayFields()将其添加.在这种情况下,请同时添加

Depending on the fields available on the Submission Dataobject, if "Document" is something you are adding as a custom column to your gridfield, you will need to add it as well using setDisplayFields(). In this case, add this as well

$config->getComponentByType('GridFieldDataColumns')->setDisplayFields(array(
    "Document" => "Link to document"
));

这篇关于SilverStripe 3.1 GridField文件链接使用HTML实体重新编写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 22:37