Codeigniter:无法解析数组

时间:2018-03-24 01:09:24

标签: php codeigniter

我从数据库中获取这样的数据

 function getdiningdata($type){
        $rest[$type]= $this->db->get_where('dining',array(
            'type'=> $type,
        ))->result();
         foreach ($rest[$type] as $value){

            $value->images  = $this->db->get_where('diningattachments',array(
                    'diningid'  => $value->id
                )
            )->result();
        }
    }

在第二个函数中我得到这样的数据

function dinewithus(){

    $data['sensi']= $this->getdiningdata('sensi');
    $this->load->view('front/dine',$data);

 }

Array
(
    [sensi] => Array
        (
            [0] => stdClass Object
                (
                    [id] => 1
                    [title] => SENSI
                    [text] => data
                    [type] => sensi
                    [images] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [id] => 1
                                    [diningid] => 1
                                    [image] => sensi3.jpg
                                )

                            [1] => stdClass Object
                                (
                                    [id] => 2
                                    [diningid] => 1
                                    [image] => sensi_last.JPG
                                )

                        )

                )

        )

)

我想在我的视图中访问$ sensi,但那不起作用。请帮助我如何在我的视图中解析数据。谢谢

1 个答案:

答案 0 :(得分:0)

您好sikandar您正在视图页面上发送名为sensi的变量数据。

$data['sensi']= $this->getdiningdata('sensi');
$this->load->view('front/dine',$data);

在视图页面上你应该得到这样的数组:我认为,

print_r($sensi->sensi);

因为变量名称为$sensi,而数组第一个元素名称也为sensi