I am trying to get the pagination to work with codeigniter. But am getting the following errors
Severity: Notice Message: Undefined offset: 0 Filename: controllers/group.php
And
Severity: Warning Message: Invalid argument supplied for foreach() Filename: views/group_list_view.php
Following is the code of my Model
public function get_list($userid)
{
$this->load->library('pagination');
$config['base_url'] = 'http://localhost/portal/index.php/group/index';
$config['total_rows'] =$this->db->where('UserId',$userid)->get('group')->num_rows();
$config['per_page'] = 10;
$config['num_links'] = 10;
$this->pagination->initialize($config);
$query['groups'] = $this->db->get('group', $config['per_page'], $this->uri->segment(3));
return $query;
}
Here is the code for my controller
class Group extends CI_Controller {
public function __constructor()
{
session_start();
parent::__constructor();
}
public function index()
{
if(!$this->session->userdata('userid'))
redirect('login');
$this->load->model('group_model');
$result = $this->group_model->get_list($this->session->userdata('$userid'));
//neither this works
data['groups'] = $result;
//nor this
$data['groups'] = $result[0];
$this->load->view('group_list_view', $data);
}
}
And this the code in view
foreach($groups as $group){
echo $group->GroupId;
}
Can anyone please guide me where am i doing it worng. Apparently no one else seems to have encountered any such problem. I followed the tutorial from net.tutsplus ditto but still facing the same issue. Please note i am new to PHP to be gentel :)