Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何阻止Silverstripe SearchContext抛出版本表\u Live错误_Search_Silverstripe - Fatal编程技术网

如何阻止Silverstripe SearchContext抛出版本表\u Live错误

如何阻止Silverstripe SearchContext抛出版本表\u Live错误,search,silverstripe,Search,Silverstripe,考虑以下Silverstripe页面类 <?php class Page extends SiteTree{ static $has_many = array('OtherDataObjects' => 'DataObjectClass'); public function getSearchContext() { $fields = new FieldSet( new TextField('Title', 'Tour'), new

考虑以下Silverstripe页面类

<?php

class Page extends SiteTree{

static $has_many = array('OtherDataObjects' => 'DataObjectClass');

public function getSearchContext() {

    $fields = new FieldSet(

        new TextField('Title', 'Tour'),
        new DropdownField('OtherDataObjects', 'Other Data Object', array('data', 'value')
    );

    $filters = array(
      'Title' => new PartialMatchFilter('Title'),
      'OtherDataObjects' => new PartialMatchFilter('OtherDataObjects.Title')
    );
    return new SearchContext(
      'Page', 
      $fields, 
      $filters
   );
  }
}
我的searchcontext搜索在我每次尝试对has\u许多关系运行搜索时都会抛出一个错误。版本化扩展似乎是罪魁祸首,因为它向所有表添加了_live,而不管基类是否具有版本化扩展。我在SilverStripe版本2.4.x和最新的3.0.x版本中遇到了相同的错误


任何帮助或提示都将不胜感激。

可以尝试使用sqlQuery。差不多

function SearchResults() {
  $select = array('*');
  $from = array('OtherDataObjects');
  $where = array('OtherDataObjects:PartialMatch' => '%' . $data['Title'] . '%');
  $sqlQuery = new SQLQuery($select, $from, $where);
  $results = $sqlQuery->execute();
  return $results;
}
$data['Title']
是搜索文本框中的值

部分匹配引用:


sql查询引用:

版本化的sitetree扩展将“live”添加到所有搜索查询中,这就是它抛出“表不存在”错误的原因。如果dataobject没有版本化的扩展,版本化的需要注意不要在sql查询前加上_live。谢谢@Gavin。我最终使用了一个定制的SQLQuery来进行搜索,它工作得非常完美。谢谢你的提示
function SearchResults() {
  $select = array('*');
  $from = array('OtherDataObjects');
  $where = array('OtherDataObjects:PartialMatch' => '%' . $data['Title'] . '%');
  $sqlQuery = new SQLQuery($select, $from, $where);
  $results = $sqlQuery->execute();
  return $results;
}