SearchController.php 919 B

123456789101112131415161718192021222324252627282930313233343536
  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');
  8. protected $_types = array('Anime' => 'app\models\Anime',
  9. 'Manga' => 'app\models\Manga',
  10. 'Kdrama' => 'app\models\Kdrama',
  11. 'anime' => 'app\models\Anime',
  12. 'manga' => 'app\models\Manga',
  13. 'kdrama' => 'app\models\Kdrama');
  14. public function index($type, $by = 'title')
  15. {
  16. $searchParam = '/' . $this->request->query['search'] . '/i';
  17. $page = $this->request->query['page'] ?: 1;
  18. //If the type part of the URL is a valid type (as defined above),
  19. if (isset($this->_types[$type]))
  20. {
  21. $model = $this->_types[$type];
  22. //Forcing search to title for now, until the search frontend is done
  23. return $model::search($searchParam, $page, 'title');
  24. }
  25. }
  26. }