Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8315421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:07:37+00:00 2026-06-08T21:07:37+00:00

I am a newbie with codeigniter and trying to learn crud in codeigniter.. My

  • 0

I am a newbie with codeigniter and trying to learn crud in codeigniter..
My site controller is :

class Site extends CI_Controller 
{
    function index()
    {
        $data = array();
        if($query = $this->site_model->get_records())
        {
            $data['records'] = $query;
        }   
        $this->load->view('options_view', $data);
    }

And my site_model is :

class Site_model extends CI_Model {
    function __construct(){
      parent::__construct();
    }


    function get_records()
    {
        $query = $this->db->get('data');
        return $query->result();
    }

    function add_record($data) 
    {
        $this->db->insert('data', $data);
        return;
    }

    function update_record($data) 
    {
        $this->db->where('id', 12);
        $this->db->update('data', $data);
    }

    function delete_row()
    {
        $this->db->where('id', $this->uri->segment(3));
        $this->db->delete('data');
    }

}

I made $autoload[‘libraries’] = array(‘database’);
When i try to check the site I get error :

Severity: Notice

Message: Undefined property: Site::$site_model

Filename: controllers/site.php

Line Number: 9

What is wrong with this code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T21:07:39+00:00Added an answer on June 8, 2026 at 9:07 pm

    Load the model:

    class Site extends CI_Controller 
    {
        //you also need the constructor
        function __construct(){
            parent::__construct();
            $this->load->model('Site_model');
        }
        function index()
        {
            $data = array();
            //now you can use it
            if($query = $this->site_model->get_records())
            {
                $data['records'] = $query;
            }   
            $this->load->view('options_view', $data);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am newbie in CodeIgniter...and i am trying to do form validation for array
Here's my model: <?php class Dbtest extends CI_Model { function __construct() { // Call
I am a newbie with PHP and CodeIgniter. I am building a CRUD app
Newbie to C++ but I am a Java programmer. Trying to learn C++ now.
Newbie to LINQ, and trying to write the following query... select f.Section_ID, f.Page_ID, f.SortOrder,
I am a newbie with codeigniter. I am trying to write an application using
I'm a newbie to ajax and trying to integrate it in to my CodeIgniter
i am newbie here in codeigniter. i was asked to build a- dooid -like-site
Im newbie here.I have a problem with codeigniter segment() method.I referred 6th segment of
newbie here, so thanks in advance for help! I have a Wordpress site with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.