我目前正在尝试使用Symfony2和Doctrine执行简单搜索。类似于这个链接:http://docs.doctrine-project.org/projects/doctrine1/en/latest/en/manual/searching.html
我目前已经设置了以下YAML文件来生成我的实体。它正确地将我的class Style实体生成为一个类。
...\Style:
type: entity
table: styles
id:
id:
type: integer
generator:
strategy: IDENTITY
actAs:
Searchable:
fields: [title]
batchUpdates: true
fields:
title:
type: string
length: 150
unique: true
在我的控制器中,我试图根据一个字符串在那个表上运行搜索。
public function searchAction($pattern)
{
$repository = $this->getDoctrine()->getRepository('..:Style');
$search = $repository->search($pattern);
return $this->outputize($search);
}
然而,当我尝试执行代码时,出现了以下异常。
Undefined method 'search'. The method name must start with either findBy or findOneBy!
我是否正确生成了实体或者我明显还缺少什么?
顺便提一下,当我在生成后查看Entity/Style.php
时,没有清晰的方法->search()
,这个功能应该由Symfony在这里生成吗?
$this->getDoctrine()
获取的可能是Doctrine 2类而不是Doctrine 1类... - AdrienBrault