PHP: NS API; hoe dit ophalen

Gestart doorDylan4 reacties31 weergaven

5 berichten · pagina 1 van 1

Dylan

Lid · Topicstarter

Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
hoi,

Ik wil alle trajecten, en vertarging ophalen waar een storing is. Dus ik heb deze funcitie:

Codeblok (voorbeeld.php):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

public function getStoringen($station, $actual = null, $unplanned = null)
{
$result = array();
$xml = $this->cache->getStoringen($station, $actual, $unplanned);
$xml = new SimpleXMLElement($xml);

foreach ($xml->Ongepland->Storing as $xmlOngeplandeStoring)
{
$id = (string)$xmlOngeplandeStoring->id;
$traject = (string)$xmlOngeplandeStoring->Traject;
$reden = (string)$xmlOngeplandeStoring->Reden;
$bericht = (string)$xmlOngeplandeStoring->Bericht;
$datum = Utils::ISO8601Date2UnixTimestamp($xmlOngeplandeStoring->Datum);
$ongeplandeStoring = new OngeplandeStoring($id, $traject, $bericht, $reden, $datum);
$result[] = $ongeplandeStoring;
}

foreach ($xml->Gepland->Storing as $xmlGeplandeStoring)
{
$id = (string)$xmlGeplandeStoring->id;
$traject = (string)$xmlGeplandeStoring->Traject;
$periode = (string)$xmlGeplandeStoring->Periode;
$reden = (string)$xmlGeplandeStoring->Reden;
$advies = (string)$xmlGeplandeStoring->Advies;
$bericht = (string)$xmlGeplandeStoring->Bericht;
$geplandeStoring = new GeplandeStoring($id, $traject, $bericht, $reden, $periode, $advies);
$result[] = $geplandeStoring;
}
return $result;
}

En ze roep ik de functie
$stations = $ns->getStoringen(, true, true);

Alleen hoe moet ik de eruit halen?

$stations->GetAdvies werkt niet?

Ik gebruik deze API: https://github.com/NS-API/PHP-API
0
Berichten
1.871
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Je kunt voor een ongeplande storing ook alleen maar getDatum() gebruiken en voor een geplande storing getDatum() en getPeriode()
0
Dylan

Lid · Topicstarter

Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Heb die API al verwijderd, ik gebruik gewoon de officiele.

Ik heb nu dit:

Output print_r:
SimpleXMLElement Object ( [Storing] => Array ( [0] => SimpleXMLElement Object ( [id] => prio-44702 [Traject] => Lelystad C.-Zwolle [Reden] => defect wissel [Bericht] => SimpleXMLElement Object ( ) [Datum] => 2013-09-07T11:31:00+0200 ) [1] => SimpleXMLElement Object ( [id] => prio-201309070956 [Traject] => Dringende herstelwerkzaamheden Zwolle-t Harde [Reden] => Dringende herstelwerkzaamheden [Bericht] => SimpleXMLElement Object ( ) [Datum] => 2013-09-07T11:07:00+0200 ) ) )

Maar als ik
echo $xml->Ongepland[0]->Reden;

doe gebeurt er niks?

Codeblok (voorbeeld.php):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

$username = xl; // gebruikersnaam van de ns api, staat in je mail
$password = x; // wachtwoord van de ns api, staat ook in je mail
$auth_token = base64_encode($username . - . $password);
$target_url = http://webservices.ns.nl/ns-api-storingen?actual=true&unplanned=true;
$ch = curl_init($target_url);
curl_setopt($ch, CURLOPT_USERPWD, $username . : . $password);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
$data = curl_exec($ch);

$xml = new SimpleXMLElement($data);

echo $xml->Ongepland[0]->Reden;

print_r($xml->Ongepland[0]);
?>
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Ik doe het zo:

[COLOR= #0000BB]<?php
$xml[/COLOR] [COLOR= #007700]=[/COLOR] simplexml_load_file[COLOR= #007700]([/COLOR][COLOR= #0000BB]$result[/COLOR][COLOR= #007700],[/COLOR]NULL[COLOR= #007700],[/COLOR] LIBXML_NOCDATA[COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$item[/COLOR] [COLOR= #007700]= ([/COLOR][URL="http://www.php.net/array"]array[/URL][COLOR= #007700])[/COLOR][COLOR= #0000BB]$xml[/COLOR][COLOR= #007700]->[/COLOR]Ongepland[COLOR= #007700];[/COLOR]
[COLOR= #0000BB]$item[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]Storing[/COLOR][COLOR= #007700]] = ([/COLOR][URL="http://www.php.net/array"]array[/URL][COLOR= #007700])[/COLOR][COLOR= #0000BB]$item[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]Storing[/COLOR][COLOR= #007700]];[/COLOR] [COLOR= #FF8000]//arrays werken in mijn ogen makkelijker....[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"FORUMCODE0"[/COLOR][COLOR= #007700];[/COLOR]
?>


Verder handel ik met Smarty de array van $item[Storing] af.
Dat komt feitelijk gewoon neer op een foreach....
0
Dylan

Lid · Topicstarter

Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Ik kijk er later wel na, eerst het systeem zelf af maken en dan ga ik wel bezig met dit
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren