SearchController.php 866 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace app\controllers;
  3. use app\models\anime;
  4. use \MongoRegex;
  5. class SearchController extends \lithium\action\Controller {
  6. public $publicActions = array('index');
  7. public function index($type, $by = "series_title")
  8. {
  9. if (empty($this->request->query['search'])) {
  10. //Redirect them or something
  11. }
  12. $searchParam = '/' . $this->request->query['search'] . '/i';
  13. $content;
  14. $limit = 20;
  15. $page = $this->request->page ?: 1;
  16. $total; //<-- number of search results
  17. switch($type)
  18. {
  19. case "anime": $content = Anime::find('all', array('conditions' => array('title' => array('like' => $searchParam)), $limit, $page));
  20. $total = Anime::count(array('title' => array('like' => $searchParam)));
  21. break;
  22. case "kdrama": break;
  23. case "manga": break;
  24. }
  25. return compact('content', 'type', 'by', 'limit', 'total', 'page');
  26. }
  27. }