| 12345678910111213141516171819202122232425262728293031323334353637 |
- <?php
- namespace app\controllers;
- use app\models\Anime;
- use \MongoRegex;
- class SearchController extends \lithium\action\Controller {
- public function index($type, $by = "series_title")
- {
- if (empty($this->request->query['search'])) {
- //Redirect them or something
- }
- $searchParam = '/' . $this->request->query['search'] . '/i';
-
- $content;
- $limit = 20;
- $page = $this->request->page ?: 1;
- $total; //<-- number of search results
- switch($type)
- {
- case "anime": $content = Anime::find('all', array('conditions' => array('title' => array('like' => $searchParam)), $limit, $page));
- $total = Anime::count(array('title' => array('like' => $searchParam)));
- break;
- case "kdrama": break;
- case "manga": break;
- }
- return compact('content', 'type', 'by', 'limit', 'total', 'page');
- }
- }
|