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?

Recommended Answers

All 7 Replies

Can you please include the full files so that we can see what is on the specific lines that are having the issues?

No, I meant the full code. So in other words it says there's an error on line 77. I want to see what line 77 looks like.

Here is the whole codes:

controllers/cwelcome.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Cwelcome extends CI_Controller {

    /**
     * Index Page for this controller.
     *
     * Maps to the following URL
     *      http://example.com/index.php/welcome
     *  - or -
     *      http://example.com/index.php/welcome/index
     *  - or -
     * Since this controller is set as the default controller in
     * config/routes.php, it's displayed at http://example.com/
     *
     * So any other public methods not prefixed with an underscore will
     * map to /index.php/welcome/<method_name>
     * @see https://codeigniter.com/user_guide/general/urls.html
     */
    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);
    }
}

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();
    }

}

views/welcome_message.php

<!DOCTYPE html>
<html lang="en">
<head>

</head>

<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>
</html>

Davy, isn't this just a duplicate of your posting here which Dani also responded to?

Yes, I realise. Sorry I just join the sponsor on the duplication. That's why I posted it twice so that I get more responds.

Have you auto load the database library?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.