从Code Igniter调用Curl(ed)json内容

时间:2013-02-08 04:07:10

标签: php codeigniter

这是我在模型中的功能

<?php
    class Clothes_model extends CI_Model {

    public function __construct()
    {
        $this->load->database();
    }

    public function get_clothes()
    {
        $url="http://192.168.0.105/ci/json_source/clothes.php";//clothes.php contain json data
        $data= this->curl->simple_get($url);
        $result = json_decode($data,true);
        return $result;
    }
}

这是我的控制器

<?php
class Clothes extends CI_Controller {

    public function __construct()
    {
        parent::__construct();
        $this->load->model('clothes_model');
    }

    public function view($result)
    {
        $data['clothes_item'] = $this->clothes_model->get_clothes();

        if (empty($data['clothes_item']))
        {
            show_404();
        }

        $data['title'] = $data['clothes_item']['title'];

        $this->load->view('templates/header', $data);
        $this->load->view('clothes/view', $data);
        $this->load->view('templates/footer');
    }
}

当我试图跑时,我收到了这个错误

  

解析错误:语法错误,意外的T_OBJECT_OPERATOR   第12行/var/www/ci/application/models/clothes_model.php

有什么不对吗?

2 个答案:

答案 0 :(得分:1)

尝试改变:

this->curl->simple_get($url);

$this->curl->simple_get($url);

确保您的$this->curl有效

答案 1 :(得分:0)

我确实喜欢这个并且适合我

    $string=file_get_contents("proj-data/food_query.php"); //place where json file is
    $decoded=json_decode($string,TRUE);