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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:53:38+00:00 2026-06-13T23:53:38+00:00

im currently working with CodeIgniter. My Front Controller loads 1 of 2 Library depending

  • 0

im currently working with CodeIgniter.
My Front Controller loads 1 of 2 Library depending on the input he gets.
Both of the librarys need access to the model.
My question:
Should I load the model in each library (plus get_instance() of CI in every Library to even get access to the CI load func) or is there any “better” solution to load the model in the Frontcontroller und ‘pass’ the model to either one or the other library. I even check the autoload possibilty but even then I dont have direct access from within the librarys.
I guess it isnt the best solution to load the model in every library (like, what if i need more libraries and so on) , but im kind of stuck right now.. 🙁

In a nutshell:

– load the model in the FrontController and maybe “pass” the model as an argument to any library I need?

– or get the instance of CI within any library und then load the model (and write redundant code)

– or is there even a way better solution?

thx in advance 🙂

edit:

I go with:

public function __construct()
{
$this->ci_instance =& get_instance();
$this->ci_instance->load->model(‘my_model’);
$this->_model = $this->ci_instance->my_model;
}

and then use the functions like this:
$mysql_result = $this->_model->get_testdata();

It is a little bit shorter than the solution from the tank auth lib (but almost the same). 🙂
But the Tank Auth Lib helped me too (to see how the pros do it).
Thx for that too dm03514!

  • 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-13T23:53:39+00:00Added an answer on June 13, 2026 at 11:53 pm

    get_instance is a native way suggested by official docs:

    for easier access to model object I would define a property in your library:

    public $_model = FALSE;
    

    somewhere in your library consructor:

    $CI =& get_instance();
    $CI->load->model('model_name');
    $this->_model = $CI->model_name;
    

    then you can access the model in any library method by calling $this->_model->method();

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

Sidebar

Related Questions

Currently i am working on xmlrpc library of codeigniter. we are fetching data from
I'm currently working on a project with Codeigniter. I have one controller called Cat
I am currently working with a codeigniter PHP based application and have come to
I am currently working on a site that is being built on codeigniter, I
I am currently working locally (myhostname.local) to begin a development project in CodeIgniter and
I'm working on a CMS in Codeigniter and I'm currently setting up some validation
I'm currently working on a project with the framework CodeIgniter. I use jQuery 1.7.1
I have been working with CodeIgniter for quite a while now and I'm currently
I am currently working on a codeigniter project, now i want a option Blog
Currently working on a bespoke ecommerce application using Codeigniter. I have a products table

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.