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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:16:38+00:00 2026-05-27T09:16:38+00:00

I’m using CodeIgniter. Let’s say I have a model for the current user and

  • 0

I’m using CodeIgniter.

Let’s say I have a model for the current user and a model for an userlist. In the model for the userlist I cache the WHERE statements because if I don’t, I have to apply them all again after the use of $this->db->count_all_results (that function resets active record functions). I off course need those also for the $this->db->get(‘users’).

The functions in the userlist model to filter users look like this:

public function onlyWomen()
{
$this->db->start_cache();
$this->db->where('gender', '1');
$this->db->stop_cache();
}

Problem is that i’m also working with a model for the current user. I suspect the cache I set in the userlist model to also copy to de current user model (i’m working with both at the same time, so I can’t flush the cache when starting with the current user model). I thought the active record cache should stay in the object in wich it is called.

How do I circumvent or resolve this?

(My English ain’t that bad, but in combination with this complicated stuff and me maybe not fully understanding objects/classes, I hope you understand my problem ^^)

  • 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-27T09:16:39+00:00Added an answer on May 27, 2026 at 9:16 am

    CodeIgniter effectively creates singletons when you load classes using the built in Loader class (for example, using $this->load->database() or $this->load->model('user')). This is why active record caching remains persistent between your Userlist and User models. There is no out of the box way to circumvent this. You would have to edit core files to implement a solution.

    Instead of creating methods for building queries through caching, why don’t you create methods for building and executing queries? Here is an example of what I mean:

    class Userlist extends CI_Model {
    
        public function get_women()
        {
            // Build and execute active record query
            $this->db->where('gender', '1');
            $query = $this->db->get('users');
    
            // Return results
            return $query->results();
        }
    
    }
    

    Edit: Adding an example of using optional parameters for specifying where clauses.

    class Userlist extends CI_Model {
    
        public function get_users($gender = false, $limit = false)
        {
            // Build active record query
            if ($gender !== false) {
                $this->db->where('gender', $gender);
            }
            if ($limit !== false) {
                $this->db->limit($limit);
            }
    
            // Execute query
            $query = $this->db->get('users');
    
            // Return results
            return $query->results();
        }
    
    }
    

    Obviously it can get a little more complicated but that is the general idea.

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

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build

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.