ну смотрите что получилось
модель
Код:
public function getMaterialsByTeacher($teacher_id=NULL, $node_id=NULL, $filter=NULL)
{
$cat = new Model_Category;
$qry = DB::select('materials.*',
array('users.name', 'name')
)
->join('users', 'left')->on('users.id', '=', 'materials.teacher_id')
->from('materials');
if ($teacher_id)
{
$qry->where('teacher_id', '=', $teacher_id);
}
if ($node_id)
{
$qry->where('node_id', '=', $node_id);
}
if (isset($filter['FIO']) && ($filter['FIO'] != ''))
{
$qry->where('name', 'like', '%'.$filter['FIO'].'%');
}
if (!$teacher_id)
{
$qry->order_by('users.name', 'asc');
}
$data = $qry->order_by('subjectName', 'asc')
->order_by('ctime', 'asc')
->execute()
->as_array();
foreach ($data as $key => $item)
{
$data[$key]['path'] = $cat->getPath($item['node_id']);
$data[$key]['isLeaf'] = $cat->isLeaf($item['node_id']);
$data[$key]['link'] = $this->getLink($item);
}
return $data->limit($pagination->items_per_page)
->offset($pagination->offset)->find_all();
}
контроллер
Код:
public function action_index()
{
$data = array();
$filter = Session::instance()->get('materialsFilter', array());
$user = Auth::instance()->get_user();
if ($this->isPressed('btnFilter'))
{
$filter['FIO'] = Arr::get($_POST, 'FIO');
Session::instance()->set('materialsFilter', $filter);
}
$material = ORM::factory('material');
if ($user->isAdmin())
{
$data['materials'] = $material->getMaterialsByTeacher(NULL, NULL, $filter);
}
else
{
$data['materials'] = $material->getMaterialsByTeacher($user->id);
}
// получаем общее количество (в моем случае) товаров
$count = ORM::factory('material')->count_all();
// передаем значение количества пользователей в модуль pagination и формируем ссылки
$pagination = Pagination::factory(array('total_items' => $count))->route_params
(array('controller' => Request::current()->controller(), 'action' => Request::current()->action(),));
$data['isAdmin'] = $user->isAdmin();
$data['filter'] = $filter;
$data['pagination'] = $pagination;
$this->tpl->content = View::factory('materials/index', $data);
}
и выдает ошибочку
ErrorException [ Fatal Error ]: Call to a member function limit() on a non-object
в этой строчке
122 return $data->limit($pagination->items_per_page)