【问题标题】:SilverStripe 3.4 Custom Reports - Set filenames as links in custom report to allow for easy editingSilverStripe 3.4 自定义报告 - 将文件名设置为自定义报告中的链接,以便于编辑
【发布时间】:2017-10-19 15:53:34
【问题描述】:

我是 SilverStripe 报告的新手,但到目前为止我还没有找到与此特定问题相关的任何内容。

我有一个自定义报告,它在网格视图中列出了网站上的所有图像和文件,但是,我想制作它,以便人们可以单击文件名并转到图像或文件进行编辑,或者每个图像和文件都有一个编辑按钮。现在,如果有人想编辑文件或图像,他们必须离开报告,进入文件选项卡,搜索所述文件/图像,然后单击进行编辑。那是相当乏味的。

我知道有一种方法可以根据 cms/code/reports 中的现有报告示例使报告中的页面标题可点击。但我没有看到与链接到上传的图像和文件有关的任何内容。

有没有办法做到这一点?

这是我的自定义报告的代码:

<?php

class CustomSideReport_ListofImagesAndFiles extends SS_Report {

    // the name of the report
    public function title() {
        return 'All Images and Files';
    }

    // what we want the report to return
    public function sourceRecords($params = null)
    {
        return File::get()
            ->sort('Title');
    }

    // which fields on that object we want to show
    public function columns() {
        return array(
            "Title" => 'Image Title',
            'Filename' => array(
                "Filename" => "Filename",
                "link" => true,
            ),
        );
    }

}

使用"link" =&gt; true 不起作用——它试图创建一个页面链接,这是不对的。我试过“编辑”和“CanEdit”。

【问题讨论】:

    标签: reporting silverstripe


    【解决方案1】:

    好的,我是通过参考断开链接报告的设置得出的:

    // which fields on that object we want to show
    public function columns()
    {
        $linkBase = singleton('CMSFileAddController')->Link('EditForm/field/File/item');
        $linkBaseEditLink = str_replace("/add","",$linkBase);
        $fields = array(
            'Title' => 'Title',
            'AbsoluteLink' => array(
                'title' => _t('CustomSideReport_ListofImagesAndFiles.ColumnFilename', 'Filename'),
                'formatting' => function($value, $item) use ($linkBaseEditLink) {
                    return sprintf('<a href="%s">%s</a>',
                        Controller::join_links($linkBaseEditLink, $item->ID."/edit"),
                        strstr($value, '/assets/', false)
                    );
                }
            )
        );
    
       return $fields;
    }
    

    我不知道这是否是有史以来最好的解决方案——它有效,而且我找不到与 SilverStripe 的这种报告创建相关的任何其他内容(我发现的所有内容都与获取 Pages 相关用于报告,而不是图像或文件。

    我不得不做一些调整,因为没有 CMSFileEditController 就像有 CMSPageEditController, 一样,但我已经完成了我所拥有的。

    如果有人有更好的解决方案,请务必分享!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-04
      • 2010-12-16
      • 2014-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-09
      相关资源
      最近更新 更多