【发布时间】:2012-07-17 18:14:45
【问题描述】:
所以我目前正在尝试使用 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生成的函数吗?
【问题讨论】:
-
请注意,symfony 2 中使用的默认学说版本是 2.x,并且您通过执行
$this->getDoctrine()得到的可能是学说 2 类而不是学说 1 类...