From b1629b5d2fbe13717fcf32fc83f40ea2e85f572f Mon Sep 17 00:00:00 2001 From: Michael Francis Date: Sun, 29 May 2011 16:36:11 -0400 Subject: Moved search into the model --- models/Anime.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'models') diff --git a/models/Anime.php b/models/Anime.php index ffa40eb..0877619 100644 --- a/models/Anime.php +++ b/models/Anime.php @@ -5,4 +5,23 @@ namespace app\models; class Anime extends \lithium\data\Model { protected $_meta = array('key' => '_id', 'source' => 'anime'); + public static function search($query, $page = 1, $by = 'title') + { + $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'); + } } \ No newline at end of file -- cgit v1.2.3