Symfony过滤器不工作 [英] Symfony Filter not working
问题描述
我的架构:
Poster:
actAs:
Timestampable: ~
Sluggable:
fields:[name]
columns:
id:
type: integer(4)
autoincrement: true
primary: true
name:
type: string(255)
notnull: true
filename:
type: string(255)
notnull: true
approved:
type: boolean(1)
default: false
start_date:
type: date
notnull: true
end_date:
type: date
notnull: true
user_id:
type: integer(20)
default: 1
attributes:
export: all
validate: true
relations:
User:
class: sfGuardUser
local: user_id
foreign: id
type: one
foreignType: many
foreignAlias: Posters
我有一个模块海报
由 doctrine生成:generate-admin
。在列表视图中,我看到所有字段的过滤器,包括 start_date
和 end_date
。现在,问题是这两个过滤器不能正常工作。例如我提供了开始日期
的范围,并按照过滤器
,在响应页面中,我看到网络调试工具栏的SQL查询
选项卡,但是我没有看到根据提供的约束约束查询的任何指示。我只是看到这一点:
I have a module poster
generated by doctrine:generate-admin
. In the list view, I see the filters for all the fields including start_date
and end_date
. Now, the problem is, that these two filters are not working as they should. e.g. I provided a range for Start Date
and pressed filter
, in the response page, I saw the SQL queries
tab of the web debug toolbar but there I don't see any indication for constraining the query according to the provided constraint. I just see this:
SET NAMES 'UTF8'
0.00s, "doctrine" connection
SELECT COUNT(*) AS num_results FROM poster p
0.00s, "doctrine" connection
SELECT s.id AS s__id, s.first_name AS s__first_name, s.last_name AS s__last_name, s.email_address AS s__email_address, s.username AS s__username, s.algorithm AS s__algorithm, s.salt AS s__salt, s.password AS s__password, s.is_active AS s__is_active, s.is_super_admin AS s__is_super_admin, s.last_login AS s__last_login, s.created_at AS s__created_at, s.updated_at AS s__updated_at FROM sf_guard_user s
0.00s, "doctrine" connection
SELECT p.id AS p__id, p.name AS p__name, p.enabled AS p__enabled, p.layout AS p__layout, p.created_at AS p__created_at, p.updated_at AS p__updated_at, p.slug AS p__slug FROM place p
0.00s, "doctrine" connection
SELECT p.id AS p__id, p.name AS p__name, p.filename AS p__filename, p.approved AS p__approved, p.start_date AS p__start_date, p.end_date AS p__end_date, p.user_id AS p__user_id, p.created_at AS p__created_at, p.updated_at AS p__updated_at, p.slug AS p__slug FROM poster p LIMIT 10
0.00s, "doctrine" connection
SELECT s.id AS s__id, s.first_name AS s__first_name, s.last_name AS s__last_name, s.email_address AS s__email_address, s.username AS s__username, s.algorithm AS s__algorithm, s.salt AS s__salt, s.password AS s__password, s.is_active AS s__is_active, s.is_super_admin AS s__is_super_admin, s.last_login AS s__last_login, s.created_at AS s__created_at, s.updated_at AS s__updated_at FROM sf_guard_user s WHERE (s.id = '2') LIMIT 1
现在,由于 Poster
模型是Timestampable, created_at
字段。我试图通过给这个字段的范围过滤结果,在查询选项卡中,我现在看到
Now, as the Poster
model is Timestampable, there is a created_at
field. I tried to filter the results by giving a range to this field, and in the queries tab, I now see
SELECT COUNT(*) AS num_results FROM poster p WHERE p.created_at >= '2011-12-15 00:00:00' AND p.created_at <= '2011-12-24 23:59:59'
这是symfony的错误吗?请帮助。
Is that a bug in symfony? Please help.
更新:好的,我做了一点调查,发现没有相应的 addFieldNameColumnQuery
function in
BasePosterFilter.class.php
。那么再一次,这是默认的symfony行为还是一些bug?
UPDATE: Ok, I did a little investigation and found that there is no corresponding addFieldNameColumnQuery
function in BasePosterFilter.class.php
. So again, is that default symfony behaviour or is that some bug?
推荐答案
Symfony不会创建任何
doctrine
(或 addFieldNameColumnCriteria
for Propel
code>),但简单的字段通过自己的类型(Number,Text,Boolean,Date,ForeignKey)映射,如您在 getFields()
中所见一个 BaseMyModelFormFilter
类,在使用输入过滤器时分配正确的过滤器。
Symfony doesn't create any addFieldNameColumnQuery
for Doctrine
(or addFieldNameColumnCriteria
for Propel
), but simply fields are "mapped" trough own types (Number, Text, Boolean, Date, ForeignKey), as you see in getFields()
of a BaseMyModelFormFilter
class, assigning the right filter when an input filter is used.
相反,如果添加一个新字段,说 myfield
,你必须创建一个函数 addMyfieldNameColumnQuery
(或 addMyfieldNameColumnCriteria
)允许Symfony获取并添加正确的sql过滤器。
Instead if you add a new field, say myfield
, you have to create a function addMyfieldNameColumnQuery
(or addMyfieldNameColumnCriteria
) to allows Symfony to get and add the right sql filter.
这篇关于Symfony过滤器不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!