如何在CodeIgniter中打印视图中的结果?

时间:2021-02-06 19:34:06

I am trying to get a result in view returned as array in controller.This is a result of an api call using the json. I need to display the results in the view. There is design integrated in view to display it. How could i do it in CodeIgniter?

我试图在视图中返回作为控制器中的数组的结果。这是使用json的api调用的结果。我需要在视图中显示结果。在视图中集成了设计以显示它。我怎么能在CodeIgniter中做到这一点?

Function call:

功能调用:

 $data['nearme_values'] = $this->swsdk->nearMe($lat, $lon, $radius, $page, $size);

This is the var_dumb result of the function call.

这是函数调用的var_dumb结果。

stdClass Object
 (   [content] => Array 
    ( [0] => stdClass Object 
        ( [id] => 1 [name] => Make America Great 
          [screenShotUrl] => http://52.77.190.221/SW/speaker_wire_images/streamSShot/stream-1479113014667.jpg
          [type] => PUBLIC [status] => RECORDED [userId] => 1 [userHandle] => abhilekh 
          [channelId] => 1 [channelName] => Sports [likes] => 0 [views] => 0 
          [liveViewers] => 0 
       ) 
      [1] => stdClass Object 
        ( [id] => 2 [name] => Make America Great 
          [screenShotUrl] => http://52.77.190.221/SW/speaker_wire_images/streamSShot/stream-1479110563909.jpg 
          [type] => PUBLIC [status] => RECORDED [userId] => 1 [userHandle] => abhilekh 
          [channelId] => 2 [channelName] => Politics [likes] => 0 [views] => 0 
          [liveViewers] => 0 
       ) 
      [2] => stdClass Object 
        ( [id] => 3 [name] => Make America Great 
          [screenShotUrl] => http://52.77.190.221/SW/speaker_wire_images/streamSShot/stream-1479109601008.jpg 
          [type] => PUBLIC [status] => RECORDED [userId] => 2 [userHandle] => sudhanshu 
          [channelId] => 3 [channelName] => Fun [likes] => 0 [views] => 0 
          [liveViewers] => 0            
      ) 
      [3] => stdClass Object 
        ( [id] => 4 [name] => Make America Great 
          [screenShotUrl] => http://52.77.190.221/SW/speaker_wire_images/profiles/pic-130.jpg 
          [type] => PUBLIC [status] => RECORDED [userId] => 2 [userHandle] => sudhanshu 
          [channelId] => 4 [channelName] => Art [likes] => 0 [views] => 0 
          [liveViewers] => 0 
      ) 
    ) [last] => 1 [totalPages] => 1 [totalElements] => 4 
      [numberOfElements] => 4 [sort] => [first] => 1 
      [size] => 10 [number] => 0 
 )

I am new to the CodeIgniter. Please support with sample code.

我是CodeIgniter的新手。请支持示例代码。

1 个解决方案

#1


0  

if you are gonna call as API, no need to put in view.

如果您要作为API调用,则无需放入视图。

Just echo like this in controller's method.

在控制器的方法中就像这样回应。

$nearme_values = $this->swsdk->nearMe($lat,$lon,$radius,$page,$size);
echo json_encode($nearme_values);

Displaying in View.

在视图中显示。

// in Controller.
    $data['nearme_values'] = $this->swsdk->nearMe($lat, $lon, $radius, $page, $size);
    $this->load->view('ur_view_file', $data);


// in view
foreach ($nearme_values->content as $nearme) {
            echo $nearme->id .' / '. $nearme->screenShotUrl .' / '. $nearme->type .'<br>';
        }

#1


0  

if you are gonna call as API, no need to put in view.

如果您要作为API调用,则无需放入视图。

Just echo like this in controller's method.

在控制器的方法中就像这样回应。

$nearme_values = $this->swsdk->nearMe($lat,$lon,$radius,$page,$size);
echo json_encode($nearme_values);

Displaying in View.

在视图中显示。

// in Controller.
    $data['nearme_values'] = $this->swsdk->nearMe($lat, $lon, $radius, $page, $size);
    $this->load->view('ur_view_file', $data);


// in view
foreach ($nearme_values->content as $nearme) {
            echo $nearme->id .' / '. $nearme->screenShotUrl .' / '. $nearme->type .'<br>';
        }