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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:28:41+00:00 2026-06-11T16:28:41+00:00

I have an architectural question that has been bothering me. Codeigniter defines there model

  • 0

I have an architectural question that has been bothering me.

Codeigniter defines there model as such. Now there are times when a model is closely tied to another. I.e. User and Security.

Is it bad practice to access another model within a model?

i.e.

class User extends CI_model 
{
    function getUser() 
    {
        $this->load->model('User');
        $user = // load user 

        $this->load->model('Security');
        $security = // load security

        $user->security = $security;
    }
}

Some how it doesn’t feel ‘kosher’ to me. It feels like I need to have a DAO or some sort of DAL on top which can then load both models and do the necessary fetching while leaving the basic CRUD and model specific operations in the model. And if we do create a separate layer, there doesn’t seem like a logical place to put them in the Codeigniter framework.

  • 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-11T16:28:42+00:00Added an answer on June 11, 2026 at 4:28 pm

    Here is the sad part: CodeIgniter does not implement MVC design pattern. It just mimics Rails architecture. There is a difference.

    What you call “models” in CodeIgniter, are usually implementation of active record (anti)pattern. They combine the responsibilities of domain business logic with storage logic.

    So, if you are working with standard CI code, then you are not supposed to do it. You cannot call $this->load->model() within another CI_Model instance, because it does no have such capabilities CI_Controller.

    Instead you would have to override default __construct(), which would access the global instance of CI and bind it to $this->load variable. Basically it would be a hack.

    You will be better off instantiating the “models” in the controller and injecting those dependencies manually.


    Then again .. you are using CodeIgniter, so who cares about development principles.

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

Sidebar

Related Questions

I know this question has been posed several times, but my goal is slightly
I know that this question has been asked previously, but before you give me
I have an architectural question on handling message ordering. For purposes of this question,
This is a pretty straightforward architectural question, however it's been niggling at me for
I have a web app, that also has an iPhone and Android app using
I realize there have already been a number of posts on n-tier design and
I have joined a rails project as a contractor. The project has been going
So I have a library I'm working on that has, or will have, optimised
I'm sure this question has already been asked in one form or another, but
This is one thing that has been bugging me for a while about DDD.

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.