如何在laravel视图中访问嵌套数组? Laravel 4 [英] How do I access nested arrays within laravel views? Laravel 4

查看:413
本文介绍了如何在laravel视图中访问嵌套数组? Laravel 4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法访问以下数组的内部值.

I am unable to access the internal values of the following array.

使对象1访问 *我使用的第一个对象中的值* 值我使用以下方法:

for Object 1 to access the *VALUES IN THE FIRST OBJECT I USED * values I used the following method:

{{$info[0]->title}} 
{{$info[0]->about}}

我正在尝试访问内部阵列中的 ...我该怎么办?

I am trying to access the VALUES IN THE INTERNAL ARRAYS... How can I?

 [

{*"pageID":1,"userID":2,"title":"CrossFit Invictus","logo":"","about":"Invictus is a 5,000 sq\/ft. fitness coaching facility equipped with men\u2019s and women\u2019s locker rooms and a designated kid\u2019s area, located in Little Italy\/Downtown San Diego, California. We offer group, semi-private and individual coaching. Our workouts are comprised of constantly varied functional movements (like pushing, pulling, squatting, lifting, running) in a manner designed to help you achieve your fitness goals.","links":"Street\r\nCar park","createdDate":"2013-10-28 14:14:40","status":1*},


    [

    {"postID":1,"author":1,"pageID":1,"type":"2","post_date":"2013-10-28 00:00:00","visibility":0,"content":"**Now I been datin this girl named Katie, she hot as hell\r\nAnd her body crazy, body shaven and it dont smell\r\nAnd I don't fall for chickens\r\nBut this one a little different\r\nBody sickening\r\nPlus she really good at making breaded chicken**","image":"EHJTRHTJ","youtube_url":"FFEFEFEWFED","is_profile":0,"likes":0,"comments":0,"post_status":1},
    {"postID":2,"author":5,"pageID":1,"type":"1","post_date":"2013-10-27 10:21:15","visibility":0,"content":"posts about empires","image":"dfsfsf","youtube_url":"efefefef","is_profile":0,"likes":0,"comments":0,"post_status":1},{"postID":6,"author":12,"pageID":1,"type":"1","post_date":"2013-10-27 00:00:00","visibility":0,"content":"post about emperors ","image":"fhfghfh","youtube_url":"hththt","is_profile":1,"likes":0,"comments":0,"post_status":1}

      ],

      [
    {"id":1,"person":1,"page":1,"reason":"blab blab blab blab blabber","positive":1, "time_posted": "**2013-10-28 15:14:43**"}
      ]


    ]

我以前将数据传递给视图的查询:

Query I used to pass data to view:

//Retrieve  BASIC PAGE INFO
        $page       = DB::table('pages')->where('pageID', $id)->first();
        $page_posts =  DB::table('pagesposts')->where('pageID', $id)->get();
        $page_likes =  DB::table('pagelikes')->where('page', $id)->get();

  //Page data 
        $info = array ($page, $page_posts, $page_likes) ;



        return View::make('testingview', compact('info'));

推荐答案

您应该像这样传递数据:

You should pass your data like this:

//Page data 
        $info = array();
        $info['page'] = $page;
        $info['page_posts'] = $page_posts;
        $info['page_likes'] = $page_likes; 

return View::make('testingview', $info);

,然后在您的视图中可以像单独的变量一样访问它:

and then in your view you can access it like separate variables:

$page, $page_posts and $page_likes

例如:

{{ $page->title }}

您应注意,调用 compact()函数会创建一个包含变量及其值的数组,这很可能是问题的根源.

You should note that invoking the compact() function creates an array containing variables and their value and this is most likely the root of your issue.

这篇关于如何在laravel视图中访问嵌套数组? Laravel 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆