问题描述
我想检查单词$ filterwords是否出现在对象之一中,并在我的小部件筛选器中对其进行过滤。
例如:
Blog1
-Feature1
--Name "Fast"
-Feature2
--Name "Beautiful"
Blog2
-Feature1
--Name "Fast"
Blog3
-Feature2
--Name "Beautiful"
在List.html中,我实际上想这样称呼我的过滤器:
<example:widget.myfilter objects="{blogs}" as="filteredblogs" property="features.name">
但这是不可能的,因为要素是n个对象。 “在关系匹配中使用了不支持或不存在的属性名称“名称”。
因此它只能这样工作:
<example:widget.myfilter objects="{blogs}" as="filteredblogs" property="features">
所以在我的小部件过滤器控制器中,我得到的属性是这样的:
/**
* @var QueryResultInterface
*/
protected $objects;
public function initializeAction()
{
$this->objects = $this->widgetConfiguration['objects'];
$this->property = $this->widgetConfiguration['property'];
$this->as = $this->widgetConfiguration['as'];
}
/**
* @param string $filterword
*/
public function indexAction(string $filterword = ""): void
{
$query = $this->objects->getQuery();
$query->matching($query->contains($this->property,$filterword));
...
现在的问题是“包含”查询不起作用,因为他必须检查属性“功能”->“名称”。但是它不会将“ Feature.name”作为属性传递,而只会传递“ features”。您必须以某种方式告诉“包含”它应该检查“名称”。
解决方法
好吧,我显然已经找到了问题。
以下内容现在可以在List.html中使用:
<example:widget.myfilter objects="{blogs}" as="filteredblogs" property="features.uid">
在控制器中:
$features = $this->featureRepository->getFeaturesByName($filterfeature);
$query = $this->objects->getQuery();
if(count($features) > 0) {
$query->matching($query->in($this->property,$features));
}
但是真正的问题显然是我已经连续连接了2个过滤器。
<example:widget.myfilter objects="{blogs}" as="filteredblogs" property="features.uid">
<example:widget.anotherfilter objects="{filteredblogs}" as="filteredmoreblogs" property="test.name">
问题在于它仅使用第二个过滤器。如果我删除第二个过滤器,第一个过滤器将起作用。