Community discussions

MikroTik App
 
User avatar
Vyrtu
newbie
Topic Author
Posts: 45
Joined: Thu Oct 03, 2013 11:49 am
Location: Torrelavega,Spain

System Identity API PEAR2

Mon Nov 04, 2013 1:45 pm

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');

?>
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: System Identity API PEAR2

Mon Nov 04, 2013 3:40 pm

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');
?>