在Codeiniter模型中将对象转换为字符串

毕宾·约翰

我的模型有3种方法,从get_state_name()和get_district_name()返回的值是对象类型,如何将其转换为字符串?当我绑定值以形成地址时,出现此错误

消息:类stdClass的对象无法转换为字符串

有谁能够帮我??

get_job_address();

get_state_name();

get_district_name();

这是我的代码

public function get_job_address($location_state_id,$district_name_id) {
    $state=$this->get_state_name($location_state_id);
    $district=$this->get_district_name($district_name_id);
    return $district.', '.$state;
}
public function get_state_name($location_state_id) {
    $this->db->select('country_name');
    $this->db->where('sid',$location_state_id);
    $this->db->limit(1);
    $query=$this->db->get('countries');
    return $query->row();
}
public function get_district_name($district_name_id) {
    $this->db->select('state_name');
    $this->db->where('sid',$location_name_id);
    $this->db->limit(1);
    $query=$this->db->get('states');
    return $query->row();
}
卡塔洛特

返回您想要的字段的值:

public function get_state_name($location_state_id) 
{
    $this->db->select('country_name');
    $this->db->where('sid',$location_state_id);
    $this->db->limit(1);
    $query=$this->db->get('countries');

    // check to make sure you got a result
    if ( $query->num_rows() == 1 ) 
    {  
        $row = $query->row(); 
        return $row->state_name ; 
    }
    // if no result return false
    else { return false; }
}

还要查看您的第三个方法get_district_name(),其中where调用了错误的变量名。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章