symfony 中单个字段的多个标准?
我试图为 symfony 中的单个字段定义多个条件,但每次定义第二个条件时,它都会覆盖前一个条件。 这是我的代码示例:
# build query to fetch search results
$c = new Criteria();
# set minimum price
if($request->getPostParameter('price_from') > 0)
{
$c->add(HomeModelPeer::PRICE,
$request->getPostParameter('price_from'),
Criteria::GREATER_EQUAL);
}
# set maximum price
if($request->getPostParameter('price_to') > 0)
{
$c->add(HomeModelPeer::PRICE,
$request->getPostParameter('price_to'),
Criteria::LESS_EQUAL);
}
有没有一种方法可以为每个字段定义多个?
I'm trying to define multiple criteria for a single field in symfony, but every time I define a second criterion, it overwrites the previous one. Here is an example of my code:
# build query to fetch search results
$c = new Criteria();
# set minimum price
if($request->getPostParameter('price_from') > 0)
{
$c->add(HomeModelPeer::PRICE,
$request->getPostParameter('price_from'),
Criteria::GREATER_EQUAL);
}
# set maximum price
if($request->getPostParameter('price_to') > 0)
{
$c->add(HomeModelPeer::PRICE,
$request->getPostParameter('price_to'),
Criteria::LESS_EQUAL);
}
Is there a way to define more than one per field?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于有两个限制的情况,您需要执行以下操作:
For the case where you have both limits, you need to do something like this: