Tign视图中的Codeigniter

时间:2018-10-13 06:26:48

标签: codeigniter twig

我正在尝试使用我网站上的facebook图表从fb粉丝页面显示最新的5条帖子。 网站基于codeigniter,但使用树枝库在视图中显示数据。

无论如何,在我在索引控制器中调用以下函数后(在索引页面上需要它),我得到了正确的json响应。

问题在于如何将json响应传递到树枝视图?

$accessToken = '123456k6';
    //The ID of the Facebook page in question.
    $id = '651393941592024';
    $attach = "https://graph.facebook.com/v2.5/$id/feed?fields=attachments,message,story&access_token=$accessToken";
    $attached = @file_get_contents($attach);
    $fbdata = json_decode($attached);
    $twigData['posts'] =    $attached;
    foreach ($fbdata->data as $post )
    {
     if(!empty($post->message)){
         $msg = $post->message;
     }
     else{
         $msg = '';
     }
         foreach ($post->attachments as $value )
    {
            foreach ($value[0]->media as $medias )
            {
                 $imgurl=$medias->src;
            }

                // echo  '<p><a href="' . $value[0]->url . '">' . $msg . '</a></p><br>';
                // echo '<p><img src="'.$imgurl.'" width="100"></p><br>';
    }
    }

这是我认为的json输出:

{"data":[{"message":"Good morning all!","story":"Andrew J Jules shared a live video to the group: Advertise Your Business or Page For Free 24\/7.","id":"673517345_2076414189089985","attachments":{"data":[{"media":{"image":{"height":405,"src":"https:\/\/scontent.xx.fbcdn.net\/v\/t15.5256-10\/s720x720\/37543897_691500211229478_2522132923675574272_n.jpg?_nc_cat=105&_nc_ad=z-m&_nc_cid=0&oh=91dce4ee7f800737aa10e34fbda37486&oe=5C5A6ABD","width":720}},"target":{"id":"691499744562858","url":"https:\/\/www.facebook.com\/AndrewJJules\/videos\/691499744562858\/"},"type":"video_inline","url":"https:\/\/www.facebook.com\/AndrewJJules\/videos\/691499744562858\/"}]}},{"story":"Idah Abdullah shared a live video to the group: Advertise Your Business or Page For Free 24\/7.","id":"100027386050133_2076413969090007","attachments":{"data":[{"media":{"image":{"height":720,"src":"https:\/\/scontent.xx.fbcdn.net\/v\/t15.5256-10\/s720x720\/41349076_173386400250894_4405193869260488704_n.jpg?_nc_cat=106&_nc_ad=z-m&_nc_cid=0&oh=7b0ea0d1f3cd87c667326291eec1b038&oe=5C56EA73","width":405}},

那是我的观点。嫩枝

<div id="post" class="panel panel-default pfPanel">
  <div class="panel-heading">
    <ul>
      <li>{{ posts }}</li>
   </ul>
  </div>
</div>

我浏览了树枝文档,并尝试了几乎所有方法来获取它,但没有结果。 任何帮助将不胜感激。

0 个答案:

没有答案