我有以下查询: (没有 addSelect(' CASE ... END as HIDDEN loquer')部分,它可以正常工作 目标是在我的评论中添加一些顺序。但是通过这部分,来自symfony的以下消息被触发:错误:预期文字,得到'''
public function myfindArticleandCommentsandScores($article,$language){
$qb = $this->createQueryBuilder('a');
$qb->leftjoin('a.comments','c')
->addSelect('c')
->leftJoin('c.scores','s')
->addSelect('s')
->leftJoin('s.user','u')
->addSelect('u')
->addSelect('
CASE
WHEN c.show = "yes" THEN 1 // PROBLEME IS HERE
ELSE 2
END AS HIDDEN show_order
')
->where(
$qb->expr()->eq('a.id', '?1'),
$qb->expr()->orX(
$qb->expr()->eq('c.langue', '?2'),
$qb->expr()->eq('c.langue', '?3')
)
)
->setParameters(array(
'1'=> $article,
'2'=> $language,
'3'=> 'EN',
))
->orderBy('show_order', 'ASC')
->addOrderBy('c.scorenote', 'DESC');
return $qb->getQuery()
->getResult();
}
我试图替换"是"与“是”'但后来我收到以下消息: FatalErrorException:Parse:语法错误,意外' oui' (T_STRING)
答案 0 :(得分:2)
使用setParameter将占位符替换为字符串或使用
"xyz='yes'"
现在代码应该是什么样的(一种可能的方式):
public function myfindArticleandCommentsandScores($article,$language){
$qb = $this->createQueryBuilder('a');
$qb->leftjoin('a.comments','c')
->addSelect('c')
->leftJoin('c.scores','s')
->addSelect('s')
->leftJoin('s.user','u')
->addSelect('u')
->addSelect('
CASE
WHEN c.show = \'yes\' THEN 1 // PROBLEME IS HERE
ELSE 2
END AS HIDDEN show_order
')
->where(
$qb->expr()->eq('a.id', '?1'),
$qb->expr()->orX(
$qb->expr()->eq('c.langue', '?2'),
$qb->expr()->eq('c.langue', '?3')
)
)
->setParameters(array(
'1'=> $article,
'2'=> $language,
'3'=> 'EN',
))
->orderBy('show_order', 'ASC')
->addOrderBy('c.scorenote', 'DESC');
return $qb->getQuery()
->getResult();
}
答案 1 :(得分:1)
应尽可能避免使用DQL中的字符串分隔符。
->addSelect('
CASE
WHEN c.show = :show THEN 1
ELSE 2
END AS HIDDEN show_order
')
->setParameter('show', 'yes')
答案 2 :(得分:0)
我添加了一个如下参数:
/*ENLARGED MODAL STYLE*/
.modal.modal-wide .modal-dialog {
max-width: 90%;
max-height: 90%;
}
.modal-wide .modal-body {
overflow-y: auto;
overflow-x: auto;
}
/*ENLARGE BUTTON STYLES*/
#enlargeElementModal,
#enlargeStrategyModal,
#enlargeVariableModal,
#enlargeTreatmentModal,
#enlargeEfficiencyModal,
#enlargeBudgetModal,
#enlargeSummaryModal{
/*transform:scale(1.3);*/
font-size: 18px;
}
/*ENLARGE MODAL PARAGRAPGH*/
#enlargeElementModal .modal-body p,
#enlargeStrategyModal .modal-body p,
#enlargeVariableModal .modal-body p,
#enlargeTreatmentModal .modal-body p,
#enlargeEfficiencyModal .modal-body p,
#enlargeBudgetModal .modal-body p,
#enlargeSummaryModal .modal-body p{
margin-bottom: 900px
}
感谢帮助我的Qoop。