Closed FezzFest closed 8 years ago
All of those requests return responses that contain one !re
reply, followed by one !done
reply. The !re
reply is the one containing the data you want, while the !done
is empty.
In your response callback, you're only checking the tag, but never the response type. Combine that with overwriting the previous response entirely (rather than appending it to a collection/array of some sort), and the result now looks obvious - you get 3 !done
replies, which don't contain any properties, because all the stuff you actually wanted was at the previous !re
reply.
To do what you want, you should either be appending stuff to the respective variables OR (in the case of these menus) you could simply detect the response type, and only replace the old one if it's a !re
reply, e.g.
public function notifyDeviceInfo(RouterOS\Response $response) {
if ($response->getType() === Response::TYPE_DATA) {
switch ($response->getTag()) {
case "deviceIdentity":
$this->identityResponse = $response;
break;
case "deviceLicense":
$this->licenseResponse = $response;
break;
case "deviceRouterboard":
$this->routerboardResponse = $response;
break;
case "deviceResource":
$this->resourceResponse = $response;
break;
}
}
or quite frankly, you should also be able to use:
public function notifyDeviceInfo(RouterOS\Response $response) {
if ($response->getType() === Response::TYPE_DATA) {
$this->{$response->getTag()} = $response;
}
if you just adjust your tag names to match the property names or vice versa.
Thank you! The code works a treat and thanks to your explanation I see where I've gone wrong :)
I have a piece of code that grabs some device information and saves it into a database. I have two classes, a RequestHandler class:
And a ResponseHandler class which defines a callback function:
Even though the commands complete successfully and the resulting variables are of the correct
RouterOS\Response
type, the response does not contain any results:I expected the response to look like this:
Do you have an idea of what could be going wrong?