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 8502171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:24:37+00:00 2026-06-11T01:24:37+00:00

I have two models, first one is dependent on the second one, and I

  • 0

I have two models, first one is dependent on the second one, and I need to call methods from the second one in the first one’s constructor.

So far I have this:

user

class User extends CI_Model {

    protected $_attributes = array();

    function __construct() {
        parent::__construct();
        $this->load->model('musers');
        foreach($this->musers->GetProfile() as $key => $val) {
            $this->_attributes[$key] = $val;
        }
    }

    function __set($key, $val) {
        return $this->_attributes[$key] = $val;
    }

    function __get($key) {
        return $this->_attributes[$key];
    }
}

I have put this model in the autoload config file and here’s what I get:

A PHP Error was encountered
Severity: Notice
Message: Undefined index: load
Filename: models/user.php
Line Number: 20

Fatal error: Call to a member function model() on a non-object in  path\to\models\user.php on line 9

There’s also something strange – the first error (notice) refers to line return $this->_attributes[$key]; while it surely should reference line $this->load->model('musers');.

I have tried loading model musers in autoload before the user model, but nothing helps. I have tried searching for this, but could not formulate the query well, I’m sure there are solutions to my problem.

As I understand this is because the constructor of the second model is called before CodeIgniter manages to load the loader class itself, but that’s pretty odd.

  • 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-11T01:24:39+00:00Added an answer on June 11, 2026 at 1:24 am

    Try:

    function __construct() {
        parent::__construct();
        $CI =& get_instance();
        $CI->load->model("musers", "musers");
        foreach($CI->musers->GetProfile() as $key => $val) {
            ......
    }
    
        ......
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Django application with two models: the first one is django.contrib.auth.User and
I have two dependent models with one to many association class Post < ActiveRecord::Base
I have two models: first one is PersonAddress , which contains info about person
I have two models: First: class CountryList < ActiveRecord::Base has_one :country, :dependent => :nullify
So I have two models: User and ScheduledSession The users have roles. One of
I have two Models, Programme and Event, a programme has many events. I need
I have two models: User and Car with the following associations: User has_many Car
I have two models User and Category that have a HABTM association. I would
I have two models like this: class ClassA(models.Model): ida = models.AutoField(primary_key=True) classb = models.ForeignKey(ClassB)
I have two models, user & offline_user, and I want to use a dropdown

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.