本文整理汇总了PHP中Model_Category::api_filter方法的典型用法代码示例。如果您正苦于以下问题:PHP Model_Category::api_filter方法的具体用法?PHP Model_Category::api_filter怎么用?PHP Model_Category::api_filter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Model_Category
的用法示例。
在下文中一共展示了Model_Category::api_filter方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: action_index
/**
* Handle GET requests.
*/
public function action_index()
{
try {
if (is_numeric($this->request->param('id'))) {
$this->action_get();
} else {
$output = array();
$cats = new Model_Category();
//make a search with q? param
if (isset($this->_params['q']) and strlen($this->_params['q'])) {
$cats->where_open()->where('name', 'like', '%' . $this->_params['q'] . '%')->or_where('description', 'like', '%' . $this->_params['q'] . '%')->where_close();
}
//filter results by param, verify field exists and has a value and sort the results
$cats->api_filter($this->_filter_params)->api_sort($this->_sort);
//how many? used in header X-Total-Count
$count = $cats->count_all();
$cats = $cats->cached()->find_all();
//as array
foreach ($cats as $category) {
$cat = $category->as_array();
//$cat['parents'] = $category->get_parents_ids();
//$cat['siblings'] = $category->get_siblings_ids();
$cat['icon'] = $category->get_icon();
$cat['price'] = i18n::money_format($category->price);
$output[] = $cat;
}
$this->rest_output(array('categories' => $output), 200, $count);
}
} catch (Kohana_HTTP_Exception $khe) {
$this->_error($khe);
return;
}
}