SearchController.php 824 B

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