Welcome Guest, Not a member yet? Register   Sign In
Getting error: Object of class CI_Output could not be converted to string
#1

I am trying to get some output from my model in JSON format, i have used the CI_Output class to set the content type and output. But whenever i try to access the view from the url, it displays the data in JSON format, but i am also getting an error, which says "http://localhost/login/index.php/json/json_output". My code is as follows:

Controller class:
<?php
class Json extends CI_Controller{
    public function __construct() {
        parent::__construct();
        $this->load->model('json_model');
    }
    public function json_output(){
        $data['json'] = 
                $this->output
                ->set_content_type('application/json')
                ->set_output(json_encode($this->json_model->get_user(),true));
        $this->load->view('json_view',$data);
        
    }
}

Model class:
<?php
class Json_model extends CI_Model{
    public function __construct() {
        parent::__construct();
        $this->load->database('login');
    }

    public function get_user(){
        $query = $this->db->get('users');
        return $query->result();
    }
}

View class:
<?php 
echo $json;
//foreach ($json as $js){
//    echo $js->user_id;
//    echo $js->username;
//    echo $js->password;
//    
//}
    

?>

Any help would be appreciated !!
Reply


Messages In This Thread
Getting error: Object of class CI_Output could not be converted to string - by Kunal - 02-29-2016, 01:36 AM



Theme © iAndrew 2016 - Forum software by © MyBB