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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:17:33+00:00 2026-05-30T06:17:33+00:00

I have a question relating to properties for a specific instance of a CI

  • 0

I have a question relating to properties for a specific instance of a CI model. For example:

There is a model called project_model. In the model it has a method calle Get_Projects:

$total_projects = $this->project_model->Get_Projects($options);

When this is called it creates a property in the model like so:

$query = $this->db->get('projects');//query

$this->num_rows = $query->num_rows();

return $query->result();

So after the method has been called and in the controller, I need to access num_rows:

$num_rows = $total_projects->num_rows;

(I know some of you may question the reason behind using num rows in the controller. It’s to do with setting the pagination. There may be better ways of doing it but there is no time in this particular project.)

My problem is that this creates a syntax error:

Severity: Notice
Message: Trying to get property of non-object
Filename: controllers/projects.php
Line Number: 110 ($num_rows = $total_projects->num_rows;)

Firstly why is this? I was thinking of using this: $this->project_model::num_rows instead? But then the num_rows won’t be specific to the $total_rows object will it? So it will just be for the entire model.

BTW: I read the CI guide on models but there wasn’t any information on creating instances of models at all.

EDITED: I need the result of num_rows property to be object-specific. So for example:

$a=$this->project_model->Get_Projects($options);
$b=$this->project_model->Get_Projects($options);
$num_rows = $this->project_model->num_rows;

The final line will get the result of $b num_rows and not $a. So How do I call it so that I can make it object-specific? (Obviously I could store it before the second call in a variable.)

  • 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-30T06:17:34+00:00Added an answer on May 30, 2026 at 6:17 am

    You could just instantiate a the model each time you need it.

    $object_one = new $this->project_model;
    $foo = $object_one->Get_Projects($options);
    var_dump($foo);
    echo $object_one->num_rows;
    
    $object_two = new $this->project_model;
    $bar = $object_two->Get_Projects($options);
    var_dump($bar);
    echo $object_two->num_rows;
    

    This way you can get/set any attributes of each model instance seperatly.

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

Sidebar

Related Questions

This question is relating to a specific functionality that a client has requested for
I have this question relating to Lucene. I have a form and I get
I have a question relating to alignment in C/C++. In Determining the alignment of
I am hoping someone can help me with a question i have relating to
I have a question relating programming and english language both: Whether to use third
I have a question relating to the timer function. I have managed to find
I have a question relating to the usage of this. Suppose I have two
there are already a few questions relating to this problem. I think my question
Ok, I have a question relating to an issue I've previously had. I know
I have a question out of curiosity relating to checking for memory leaks. Being

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.