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

  • SEARCH
  • Home
  • 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 6052349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:55:09+00:00 2026-05-23T07:55:09+00:00

First the Model class: class Xxxx_model extends Model { function XxxxModel() { parent::Model(); $this->load->database();

  • 0

First the Model class:

    class Xxxx_model extends Model
    {
      function XxxxModel()
      {
        parent::Model();
        $this->load->database();
      }

      function isInDatabase()
      {
        // Please ignore the sql query, it's just to show some random sql code with results
11.      $result = $this->db->query('SELECT * FROM someTable WHERE ...');
        $numberOfRows = $result->num_rows();
        ... 
        return $test;
      }
    }

Now the controller:

function someLogic()
{
  $this->load->model('xxxx_Model', 'xxxxModel'); // not necessary to specify
  $this->xxxxModel->isInDatabase();
}

When I run this I get the error:

Severity: Notice  --> Undefined property: Xxxx_model::$db .../xxxx_model.php line 11

I have no idea why this is. If I put the db code in the controller it seems to work, it’s only with this setup in the model that it fails. I can’t for the life of me figure out where the code is astray…

  • 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-05-23T07:55:09+00:00Added an answer on May 23, 2026 at 7:55 am

    To add to atno’s answer:

    class Xxxx_model extends Model
    {
      function XxxxModel() //<--- does not match model name Xxxx_model
      {
        parent::Model();
        $this->load->database();
      }
    

    Basically, you are not constructing the class or the parent class Model. If you are on PHP5, you may use __construct(), otherwise you must match the class name exactly, regardless of what alias you load it with in your controller. Example:

    class Xxxx_model extends Model
    {
      function __construct()
      {
        parent::__construct(); // construct the Model class
      }
    }
    

    I may be mistaken (haven’t used 1.x in a while), but if you construct the Model class, there’s no need to load the database if you are using the default connection settings in config/database.php, it should already be loaded for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following model : class Model extends BaseModel { public function save($conn
This is my model: class Author(models.Model): first_name = models.CharField(max_length=200) last_name = models.CharField(max_length=200) middle_name =
I have this Task model: class Task < ActiveRecord::Base acts_as_tree :order => 'sort_order' end
first time using Asp.Net MVC here. I have a model class defined with 3
I've got a zend framework model: class User extends Zend_Db_Table_Abstract { protected $_name =
The Code-First model: public class Princess { public int Id { get; set; }
I have an entity class (using model first, if that matters) that should persist
I have this model: class People(models.Model): name = models.CharField(max_length=128, db_index=True) friends = models.ManyToManyField('self') So
I am using Entity Framework Code First to create a database table. My model
Let's take the Django tutorial. In the first part we can find this model:

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.