将旧的 silverstripe 形式转换为 SS 3

Convert old silverstripe form to SS 3

我有一个旧的 SS2.4 站点,我已更新到 SS3.1.13。我无法使用旧站点的唯一部分是过滤 DataObjects 的搜索表单。旧代码是:

public function doCollectionSearch($data, $form)
{
    $filters = array();
    ...
    //setup some filters based on user selections
    ...
    $where = implode(" AND ", $filters);

    if(!isset($_REQUEST['start'])) $_REQUEST['start'] = 0;
    $limit = $_REQUEST['start'].",50";

    return $this->customise(array(
        'Collections' => DataObject::get("Collection", $where, "Genus, Species ASC", null, $limit)
    ))->renderWith(array('Collection_results','Page'));
}

我已将最后一部分更新为:

    return $this->customise(array(
        'Collections' => Collection::get()->where($where)->sort("Genus, Species ASC")->limit($limit)
    ))->renderWith(array('Collection_results','Page'));

但是我得到了 "the method 'fortemplate' does not exist on 'CollectionPage_Controller'"。

我知道 $where 还不对,但如果我去掉它,我仍然会收到错误..

我知道我遗漏了一些明显的东西...任何人都可以提出修复建议吗?

如果您的模板访问的方法或数据库字段returns 是一个无法缩减为字符串的对象,您将收到该错误。当您有一个相关对象(比如父页面)并且您执行以下操作时,通常会发生这种情况:

<p>My parent is: $Parent</p>

而不是

<p>My parent is: $Parent.Title</p>

2.4 中存在同样的事情,所以这并不能完全解释你的问题,但我会在你的模板中寻找类似上述场景的东西。