Joomla json输出组件2.5从控制器到视图

时间:2013-01-10 10:19:05

标签: php json variables joomla components

我为你做了一件事,我有一个JSON Api,它给了我一些信息,其中一些没用。

使用以下代码行,我可以调用所有信息并写入我的视图:

    $url = 'http://apisurl.com/prequalify/json/'.$postcode.'/'.$huisnummer.'';
    $content = file_get_contents($url);
    $json = json_decode($content);

发送到视图:

$view->assignRef('info', $content);

这是我正常的PHP代码:

foreach ($json['enduserinfo'] as $item) {
        echo " Postcode: {$item['zipcode']}
        <br /> Huisnummer: {$item['housenr']}
        <br /> Straatnaam: {$item['street']}
        <br /> Woonplaats: {$item['city']}
        <br /> Centrale: {$item['centrale']}
        <br /> Toegangspunt: {$item['access-area']}
        <br /> Isra: {$item['isra']}";
    }

如何在Joomla中获得相同的结果?

对我来说真正的问题是我不需要al信息,我想设置一些变量来存储正确的数据。并且只将它们发送到我的视图。现在结果只是我页面中的一个完整的JSON文件。

在我的普通php脚本中,来自Joomla的extern工作正常。 Joomla有特殊的方式来做这件事吗?

请帮助

1 个答案:

答案 0 :(得分:0)

在您的控制器中,您应该执行以下操作:

$myJson = json_decode($content, true); // will make it as associative array
$theIndexIwantToSendToTheView = $myJson['enduserinfo'];
//send to view the variable $theIndexIwantToSendToTheView

现在,您可以使用变量$myJson

处理 json

这将解决您的问题。