Codeigniter-无法将类__PHP_Incomplete_Class的对象转换为字符串 [英] Codeigniter - Object of class __PHP_Incomplete_Class could not be converted to string

查看:45
本文介绍了Codeigniter-无法将类__PHP_Incomplete_Class的对象转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我回显 is_active 变量时,我得到了一个__PHP_Incomplete_Class类的对象无法转换为字符串错误,我可以使用用户名和is_logged_in正常工作变量,但是没有is_active变量,我想知道我在这里可能做错了什么...

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");

我的模型函数:

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

        return $result;
    }

在我看来:

$is_active= $this->session->userdata("is_active");
                echo $is_active;


推荐答案

在模型中更改

In your model change the return line from

return $result;

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

查询将CodeIgniter对象传递给<$ c之后,它甚至还不是结果$ c> 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.

这篇关于Codeigniter-无法将类__PHP_Incomplete_Class的对象转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆