0
codeigniter보기에서 json 데이터를 반환하려고합니다. 하지만 내 코드가 작동하지 않습니다. 나는이 사이트에서 주어진 모든 옵션을 시도했습니다. 하지만 난보기에서 json 데이터를 반환 할 수 없습니다 이것은 컨트롤러 코드입니다.codeginiter json 출력 오류
<?php
class Json extends CI_Controller
{
function __construct()
{
parent::__construct();
}
public function index()
{
$this->load->model('get_json');
$data['message']=$this->get_json->get_fruits();
if ($data!== false)
{
$this->load->view('json',json_encode($data['message']));
}
}
}
내 모델
<?php
class get_json extends CI_Model
{
function __construct()
{
parent::__construct();
}
function get_fruits()
{
$sql = "SELECT * FROM fruit where name='Apple'";
$query = $this->db->query($sql);
// Fetch the result array from the result object and return it
return $query->result();
}
}
보기 코드 :
<?php
$this->output->set_content_type('application/json');
echo $message;
내 코드가 잘못 wwhere 도와주세요. 이것에
ERROR - 2012-05-11 15:28:40 --> Severity: Notice --> Undefined variable: message C:\xampp\htdocs\ci\system\core\Loader.php(829) : eval()'d code 3
DEBUG - 2012-05-11 15:28:40 --> File loaded: application/views/json.php
+1 정보는보기에 적합하지 않습니다. 내 컨트롤러의 – gorelative
에코가 작동하지 않습니다. iam은 여전히 수정을 찾았습니다. [link] http://stackoverflow.com/questions/10520423/echo-in-codeignter-controller-is-not-working [/ link] – user1130639
+1 좋은 답변입니다. – Adam