SearchController.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace app\controllers;
  3. use app\models\Anime;
  4. use app\models\Manga;
  5. use app\models\Kdrama;
  6. class SearchController extends \lithium\action\Controller {
  7. public $publicActions = array('index', 'anime', 'manga', 'kdrama');
  8. public function index() {
  9. if (isset($this->request->query['q']))
  10. {
  11. $q = $this->request->query['q'];
  12. $conditions = array('title' => array('like' => "/$q/i"));
  13. $limit = 7;
  14. $anime = Anime::find('all', compact('conditions', 'limit'));
  15. $manga = Manga::find('all', compact('conditions', 'limit'));
  16. $kdrama = Kdrama::find('all', compact('conditions', 'limit'));
  17. return compact('q', 'anime', 'manga', 'kdrama');
  18. }
  19. }
  20. public function anime($by = 'title')
  21. {
  22. $q = isset($this->request->query['q']) ? $this->request->query['q'] : '';
  23. $page = isset($this->request->query['page']) ? $this->request->query['page'] : 1;
  24. return Anime::search("/$q/i", $page, 'title');
  25. }
  26. public function manga($by = 'title')
  27. {
  28. $q = isset($this->request->query['q']) ? $this->request->query['q'] : '';
  29. $page = isset($this->request->query['page']) ? $this->request->query['page'] : 1;
  30. return Manga::search("/$q/i", $page, 'title');
  31. }
  32. public function kdrama($by = 'title')
  33. {
  34. $q = isset($this->request->query['q']) ? $this->request->query['q'] : '';
  35. $page = isset($this->request->query['page']) ? $this->request->query['page'] : 1;
  36. return Kdrama::search("/$q/i", $page, 'title');
  37. }
  38. }