I am trying this paging simulation but I have not yet successful.
models/name_model.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Name_model extends CI_Model {
public function __construct()
{
parent::__construct();
}
public function get_name($num, $offset)
{
$query = $this->db->get('name', $num, $offset);
return $query->result();
}
}
controllers/cwelcome.php
public function index($id=NULL)
{
$this->load->model('name_model');
$this->load->library('pagination');
$config['base_url'] = 'http://www.gsa-constructionspecialist.com/articles/article';
$config['total_rows'] = 15;
$config['per_page'] = 5;
$this->pagination->initialize($config);
$data['halaman'] = $this->pagination->create_links();
$data['query'] = $this->name_model->get_name($config['per_page'], $id);
$this->load->view('welcome_message', $data);
}
views/welcome_message.php
<body>
<?php
//kalo data tidak ada didatabase
if(empty($query))
{
echo "<tr><td colspan=\"6\">Data tidak tersedia</td></tr>";
}else
{
$no = 1;
foreach($query as $row)
{
?>
<tr>
<td><?php echo $row->name;?></td>
</tr>
<?php
$no++;
}}
?>
</table>
<div class="halaman">Halaman : <?php echo $halaman;?></div>
</body>
Here is the error messages:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Cwelcome::$db
Filename: core/Model.php
Line Number: 77
Backtrace:
File: C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\Paging\application\models\name_model.php
Line: 13
Function: __get
File: C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\Paging\application\controllers\Cwelcome.php
Line: 35
Function: get_name
File: C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\Paging\index.php
Line: 315
Function: require_once
Fatal error: Call to a member function get() on a non-object in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\Paging\application\models\name_model.php on line 13
A PHP Error was encountered
Severity: Error
Message: Call to a member function get() on a non-object
Filename: models/name_model.php
Line Number: 13
Backtrace:
Line Number: 13
models/name_model.php
$query = $this->db->get('name', $num, $offset);
How to fix the error message?