Example #1
0
 /**
  * Display pages list.
  */
 public function actionIndex()
 {
     $model = new Page('search');
     if (!empty($_GET['Page'])) {
         $model->attributes = $_GET['Page'];
     }
     $dataProvider = $model->search();
     $dataProvider->pagination->pageSize = Yii::app()->settings->get('core', 'productsPerPageAdmin');
     $this->render('index', array('model' => $model, 'dataProvider' => $dataProvider));
 }
Example #2
0
    $page->title = 'Search';
    $page->slug = 'search';
    if ($offset <= 0) {
        return Response::create(new Template('404'), 404);
    }
    // Convert custom escaped characters and escape MySQL special characters.
    // http://stackoverflow.com/questions/712580/list-of-special-characters-for-sql-like-clause
    $term = str_replace(array('-sl-', '-bsl-', '-sp-', '%', '_'), array('/', '\\\\', ' ', '\\%', '\\_'), $slug);
    // Posts, pages, or all
    if ($whatSearching === 'posts') {
        list($total, $results) = Post::search($term, $offset, Post::perPage());
    } elseif ($whatSearching === 'pages') {
        list($total, $results) = Page::search($term, $offset);
    } else {
        $postResults = Post::search($term, $offset, Post::perPage());
        $pageResults = Page::search($term, $offset);
        $total = $postResults[0] + $pageResults[0];
        $results = array_merge($postResults[1], $pageResults[1]);
    }
    // search templating vars
    $safeTerm = eq(str_replace(array('\\\\', '\\%', '\\_'), array('\\', '%', '_'), $term));
    Registry::set('page', $page);
    Registry::set('page_offset', $offset);
    Registry::set('search_term', $safeTerm);
    Registry::set('search_results', new Items($results));
    Registry::set('total_posts', $total);
    return new Template('search');
});
Route::post('search', function () {
    // Search term, placeholders for / and \
    $term = str_replace(array('/', '\\', ' '), array('-sl-', '-bsl-', '-sp-'), Input::get('term', ''));