Comments (4)
You should check that page in the wiki that says "API Reference".
It has detailed information on all methods and classes in the package. In this case, you're asking about Util::getAll() and ResponseCollection.
To answer your specific questions though, you can read a ResponseCollection as if you would read an array - a foreach loop, or a for loop with a count(), and as you can see in the reference, there are also a few extra methods for filtering it and sorting the responses.
Each response in the ResponseCollection, you can also read as if you were reading an associative array (for properties), and there are a few extra methods for accessing things that are not properties (type and tag). So in its simplest form, you can think of a ResponseCollection as an array of associative arrays. e.g.
foreach ($array as $response) {
foreach ($response as $propName => $propValue) {
echo 'The property "' . $propName . '" has a value "' . $propValue . '". ';
}
}
And yes, just as you can use a "where" from a command line, you can use a RouterOS\Query
object as the second argument of getAll() to return only items matching a criteria, in this case, all where the MAC address is a certain one, f.e.
$array = $util->setMenu('/ip dhcp-server lease')
->getAll(array(), RouterOS\Query::where('mac-address', 'B0:E8:92:30:C9:4D'));
As you can see in the reference, the first argument is extra arguments to pass to the "print" request.
from net_routeros.
On our company router we have two networks, public and private.
I've connected to both for testing purposes. And when I search by MAC I get the following error:
Fatal error: Uncaught PEAR2\Net\RouterOS\RouterErrorException: Error getting property in /var/www/.../PEAR2/Net/RouterOS/Util.php:561
Stack trace:
#0 /var/www/.../mtk_test.php(68): PEAR2\Net\RouterOS\Util->get('*2f32*2f57')
#1 {main}
Response collection:
Array
(
[0] => PEAR2\Net\RouterOS\Response Object
(
[unrecognizedWords:protected] => Array
(
)
[_type:PEAR2\Net\RouterOS\Response:private] => !trap
[attributes:protected] => Array
(
[message] => invalid internal item number
)
[_tag:PEAR2\Net\RouterOS\Message:private] =>
)
[1] => PEAR2\Net\RouterOS\Response Object
(
[unrecognizedWords:protected] => Array
(
)
[_type:PEAR2\Net\RouterOS\Response:private] => !done
[attributes:protected] => Array
(
in /var/www/.../PEAR2/Net/RouterOS/Util.php on line 561
Totally crashes my script.
Is it possible for catch{}
to return the message [message] => invalid internal item number
?
from net_routeros.
First off, assuming you used Util::find() with a Query (and you then passed the result to Util::get()), the cause is probably this issue. I'll release a new fixed version soon, though if you want it "now", you can use Composer with "dev-develop" as the version of "pear2/net_routeros" to get.
But in general, yes, as the error message itself says, this is an uncaught exception, meaning you can catch it if you want, and deal with it, f.e.
try {
$address = $util->get($util->find(RouterOS\Query::where('mac-address', 'B0:E8:92:30:C9:4D')), 'address');
} catch (RouterOS\RouterErrorException $e) {
echo 'Router message: ' . $e->getResponses()->getAllOfType(RouterOS\Response::TYPE_ERROR)->getProperty('message');
}
from net_routeros.
Thanks.
Error message is returned this way.
However theres a Notice you might want to look into for the next update.
Notice: Array to string conversion in /var/www/.../PEAR2/Net/RouterOS/Util.php on line 488
from net_routeros.
Related Issues (20)
- utils find implementation error HOT 4
- Error installing with composer HOT 3
- Error in Codeigniter HOT 7
- phar file for download? HOT 1
- Getting router MAC address HOT 3
- 6.45.8 - authentication failure HOT 2
- Hi, i already updated script to login with version 6.43.
- Caracters <> doesnt show ? HOT 2
- Unable to connect to the router HOT 4
- Authentication problem from RouterOS 6.45.6 HOT 1
- Workflow question HOT 4
- $response->getType return "!re" - what's going on? HOT 2
- "LIKE" in query HOT 1
- Best practice to add a large list HOT 4
- exec() problem HOT 2
- Persistent connection HOT 3
- Call "all" option on Hotspot Server submenu to use in Users submenu HOT 3
- Why can't I enable, disable or remove Hotspot Users? HOT 2
- Unable to login ROS v6.47.10 (long-term)
- Random Mac Address HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from net_routeros.