/** * Handle GET requests. */ public function action_index() { try { if (is_numeric($this->request->param('id'))) { $this->action_get(); } else { $output = array(); $orders = new Model_Order(); //filter results by param, verify field exists and has a value and sort the results $orders->api_filter($this->_filter_params)->api_sort($this->_sort); //how many? used in header X-Total-Count $count = $orders->count_all(); //by default sort by created date if (empty($this->_sort)) { $this->_sort['created'] = 'desc'; } //after counting sort values $orders->api_sort($this->_sort); //pagination with headers $pagination = $orders->api_pagination($count, $this->_params['items_per_page']); $orders = $orders->cached()->find_all(); //as array foreach ($orders as $order) { $output[] = self::get_order_array($order); } $this->rest_output(array('orders' => $output), 200, $count, $pagination !== FALSE ? $pagination : NULL); } } catch (Kohana_HTTP_Exception $khe) { $this->_error($khe); } }