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:


            $data = array(
                "username" => $this->input->post("username"),
                "is_logged_in" => true,
                "is_active" => $activated_val

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;


    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.

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



  • ¥20 Apache poi使用问题
  • ¥21 matlab怎么求时域信号的二阶导数
  • ¥15 判断两个表是否完全相同
  • ¥15 java map类型数据格式,如何快速通过前缀匹配元素
  • ¥15 stc12c5a60s2、QMC5883L、LCD1602组合测量磁场所需程序
  • ¥20 Win11测试yolov4,“找不到nvcuda.dll”怎么办?
  • ¥15 simulink绘制bode图
  • ¥15 php_network_getaddresses: getaddrinfo failed: Name or service not known
  • ¥15 用msg发消息出现的问题
  • ¥15 unity3d机械臂