Page 1 of 1

System Identity API PEAR2

Posted: Mon Nov 04, 2013 1:45 pm
by Vyrtu
Hi again :)

I tried print a name of my mikrotik router and it returns nothing :S

This is the code:

php code

<?php

use PEAR2\Net\RouterOS;
// require_once 'pear2\src\PEAR2\Autoload.php';
require_once 'PEAR2_Net_RouterOS-1.0.0b4.phar';


$client = new RouterOS\Client('xx.xxx.xx.xxx', 'victor', 'xxxxx');


$cabecera = new RouterOS\Request('/system/identity/print');
return $cabecera('name');

?>

Re: System Identity API PEAR2

Posted: Mon Nov 04, 2013 3:40 pm
by boen_robot
You need to actually send the request. $cabecera merely contains a description of what you'd eventually be sending (command, arguments, etc.).

To send a request, you use $client, and it's sendSync() or sendAsync() method in particular, and give it the request, which will then be sent.

Also, "return" works within a function/method or an included file. If you want to print it on screen directly, you'd want to use "echo" insted.

E.g.

php code

<?php

use PEAR2\Net\RouterOS;
// require_once 'pear2\src\PEAR2\Autoload.php';
require_once 'PEAR2_Net_RouterOS-1.0.0b4.phar';

$client = new RouterOS\Client('xx.xxx.xx.xxx', 'victor', 'xxxxx');

$cabecera = new RouterOS\Request('/system/identity/print');
$cabecera_result = $client->sendSync($cabecera);

echo $cabecera_result('name');
?>