本文整理匯總了PHP中headers::model方法的典型用法代碼示例。如果您正苦於以下問題:PHP headers::model方法的具體用法?PHP headers::model怎麽用?PHP headers::model使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類headers
的用法示例。
在下文中一共展示了headers::model方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: actionIndex
/**
* Prepares a list of products and renders accordingly
*
* If the request comes from an AJAX request containing pagination data, the resultant table will be
* paginated appropriately. Otherwise, a default pagination state (no sorting, no filtering, page 1)
* will be created.
*/
public function actionIndex()
{
$statuses = statuses::model()->getAll();
$vendors = vendors::model()->getAll();
$tags = tags::model()->getAll();
$showColumns = Auth::User()->getColumns();
if (count($showColumns) == 0) {
$showColumns = array(1, 2, 3);
}
$columnHeaders = headers::model()->getAll();
$allHeaders = array();
foreach ($columnHeaders as $header) {
$allHeaders[$header->id] = $header;
}
$headers = array('show' => $showColumns, 'headers' => $allHeaders);
$pagination = array('limit' => array(0, 10), 'filter' => 'All categories', 'sortAttribute' => null, 'sortDirection' => null);
if (!empty($_GET['ajax'])) {
//handle ajax requests
//get the pagination data from the query string
if (isset($_GET['headers'])) {
$headers['show'] = explode(',', $_GET['headers']);
Auth::User()->setColumns($_GET['headers']);
}
$sortHeader = headers::model()->getbyPK($_GET['sortAttribute']);
$pagination['sortAttribute'] = $sortHeader->sortName;
$pagination['sortDirection'] = $_GET['sortDirection'];
$pagination['limit'] = array($_GET['paginationPageNumber'], $_GET['paginationPerPage']);
$pagination['filter'] = $_GET['filter'];
$conditions = null;
$params = null;
//if there is a filter in place, create the conditions and parameters needed
if (!empty($pagination['filter']) && $pagination['filter'] != 'All categories') {
$conditions = "category = :category";
$category = categories::model()->getByAttribute('name', $pagination['filter']);
$params = array('category' => $category->id);
}
$models = items::model(true)->getAll($conditions, $params, $pagination);
$count = items::model()->getCount($conditions, $params);
$pagination['count'] = $count;
$pagination['sortAttribute'] = $_GET['sortAttribute'];
$this->renderPartial('table', array('data' => $models, 'statuses' => $statuses, 'pagination' => $pagination, 'vendors' => $vendors, 'tags' => $tags, 'headers' => $headers));
} else {
//handle default requests
$models = items::model(true)->getAll(null, null, $pagination);
$count = items::model()->getCount(null);
$pagination['count'] = $count;
$this->render('index', array('models' => $models, 'statuses' => $statuses, 'vendors' => $vendors, 'tags' => $tags, 'pagination' => $pagination, 'headers' => $headers));
}
}