0

I'm getting a Object of class __PHP_Incomplete_Class could not be converted to string error when I echo my is_active variable, I can work just fine with the username and is_logged_in variable, but not with the is_active variable, I'm wondering what I could be doing wrong here...

On my controller I did:

$username=$this->input->post("username");
            $activated_val=$this->membership_model->is_activated($username);

            $data = array(
                "username" => $this->input->post("username"),
                "is_logged_in" => true,
                "is_active" => $activated_val
            );
            $this->session->set_userdata($data);
            redirect("main");

My model function:

function is_activated($username){
        $query = "SELECT activated FROM members WHERE username=?";
        $result = $this->db->query($query, $username);

        return $result;
    }

And in my view:

$is_active= $this->session->userdata("is_active");
                echo $is_active;
3
  • What type is $activated_val? Normally storing objects in a session is not a good idea Commented Sep 27, 2012 at 23:35
  • In my table, the "activated" column is of the INT type. Commented Sep 27, 2012 at 23:38
  • And what type is $activated_val variable? var_dump($activated_val); Php says it's an object Commented Sep 27, 2012 at 23:39

1 Answer 1

2

In your model change the return line from

return $result;

to

return $result->row()->activated;

The query returns a CodeIgniter object which is not even a result yet, after passing it to row() you get an object with your database column values as this object attributes, then you refer to the activated column value by getting(->activated) the corresponding attribute of this object.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.