我在理论中使用symfony 1.4,当搜索词包含点(例如:"V-5.26 3.15“)时,我遇到了这个问题:
找不到"%V-5“类
这是我的密码
$products = Doctrine_Query::create()
->select('t.name,p.price,p.id,pi.immagine,p.offer,p.special,t.description')
->from('Products p')
->leftJoin('p.ProductsImages pi')
->leftJoin('p.Translation t WITH t.lang = ?', $this->getUser()->getAttribute('current_lang'))
->where('p.active = ?', '1')
->andWhere('pi.ordine = ?', 0);
$term = explode(' ', $request['term']);
$ricerca = '';
for($i=0; $i < count($term); $i++) {
$products->andWhere(' t.name LIKE "%'. $term[$i] .'%" OR t.description LIKE "%'. $term[$i] .'%" ');
}
$products->orderBy('t.name');
$this->pager = new sfDoctrinePager('Products', sfConfig::get('app_max_page_products'));
$this->pager->setQuery($products);
$this->pager->setPage($request->getParameter('page', 1));
$this->pager->init();
$term = explode(' ', $request['term']);
$ricerca = '';
for($i=0; $i < count($term); $i++) {
$products->andWhere(' t.name LIKE "%'. $term[$i] .'%" OR t.description LIKE "%'. $term[$i] .'%" ');
}
$products->orderBy('t.name');
$this->pager = new sfDoctrinePager('Products', sfConfig::get('app_max_page_products'));
$this->pager->setQuery($products);
$this->pager->setPage($request->getParameter('page', 1));
$this->pager->init();有什么解决办法吗?非常感谢。
发布于 2014-05-05 16:40:34
在构造查询时应使用参数:
$products->andWhere(
't.name LIKE ? OR t.description LIKE ?',
array('%'.$term[$i].'%', '%'.$term[$i].'%')
);https://stackoverflow.com/questions/23475928
复制相似问题