dsdzvprlp51692469 2012-09-27 23:30
浏览 73
已采纳

Codeigniter - 类__PHP_Incomplete_Class的对象无法转换为字符串

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;
  • 写回答

1条回答 默认 最新

  • doupang3062 2012-09-27 23:41
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动