Skip to content

Instantly share code, notes, and snippets.

@kemo
Created May 26, 2011 13:35
Show Gist options
  • Save kemo/993151 to your computer and use it in GitHub Desktop.
Save kemo/993151 to your computer and use it in GitHub Desktop.
Kohana Search controller example
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Search extends Controller {
/**
* @var Database_Result
*/
protected $_results;
/**
* @var Pagination
*/
protected $_pagination;
public function action_cars($page = 1)
{
$cars = new Model_Car;
$count = $cars
->set_search_data($this->request->query())
->reset(FALSE)
->count_all();
$this->_pagination = Pagination::factory(array(
'current_page' => array('source' => 'route', 'key' => 'page'),
'items_per_page' => 15,
'total_items' => $count,
));
$this->_results = $cars
->limit($this->_pagination->items_per_page)
->offset($this->_pagination->offset)
->find_all();
}
public function after()
{
/**
* Decide what to respond with depending on the Accept header
*/
switch ($this->request->headers('Accept'))
{
default :
$this->view = new View_Search_Results;
$this->view->set(array(
'cars' => $this->_results,
'pagination' => $this->_pagination,
));
break;
}
return parent::after();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment