Pārlūkot izejas kodu

Fixed issue with special_id, since special_id isn't a regex, we drop 'like' from the search params

Michael Francis 14 gadi atpakaļ
vecāks
revīzija
4dd797ca02
1 mainītis faili ar 28 papildinājumiem un 14 dzēšanām
  1. 28 14
      models/Anime.php

+ 28 - 14
models/Anime.php

@@ -7,21 +7,35 @@ class Anime extends \lithium\data\Model {
 
 	public static function search($query, $page = 1, $by = 'title') 
 	{
-			$defaults = array(
-				'limit' => 20 
-				);
+		$defaults = array('limit' => 20);
 		$limit = 20;
 
-		$content = self::find('all',
-			array(
-				'conditions' => array(
-					$by => array('like' => $query)
-				),
-				'limit' => $limit,
-				'page' => $page
-			));
-	
-		$total = Anime::count(array('title' => array('like' => $query)));
-		return compact('content', 'by', 'limit', 'total', 'page');
+		switch($by) {
+			case 'special_id':
+			
+			$content = self::find('first',
+				array('conditions' => array(
+						$by => $query
+					),
+					'limit' => $limit,
+					'page' => $page
+				));
+
+
+		
+			$total = Anime::count(array($by => $query)); 
+			break;
+			
+			default:
+			$content = self::find('all',
+				array('conditions' => array(
+						$by => array('like' => $query)
+					),
+					'limit' => $limit,
+					'page' => $page
+				));
+				$total = Anime::count(array($by => array('like' => $query)));
+	}
+	return compact('content', 'by', 'limit', 'total', 'page');
 	}
 }