Question

I'm using symfony 1.4 with doctrine and i have this problem when the search word contains the point (example: "V-5.26 3.15"):

Couldn't find class "%V-5

this is my code

$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();

any solutions please? thanks a lot.

Was it helpful?

Solution

You should use parameters when constructing queries:

$products->andWhere(
    't.name LIKE ? OR t.description LIKE ?',
    array('%'.$term[$i].'%', '%'.$term[$i].'%')
);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top