Forum Discussion
Eric_Hampton_26
Nimbostratus
Aug 21, 2008iControl, PHP, and Arrays
While searching for a solution to the same problem I noticed most threads regarding PHP and iControl had issues with the multi-dimensional arrays. The main one being something like this: WideIPPool [] []. It is defined in the SDK as a 2 dimensional array, however, in PHP it needs to be defined as a 3 dimensional array.
Example:
If we were to use a 2 dimensional array:
$soapClient->create(array('hostname'), array(3), array(array('pool_name' => 'hostname-pool01', 'order' => 1, 'ratio' => 1)), array(array('rule_name' => 'name1', 'priority' => 1)));
This creates the soap request:
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns2="urn:iControl" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
hostname
3
Clearly the portion for WideIPPool is incorrect, theres no data!! This is because it expects a sequence first (array 1), then an array of pools (array 2), finally the definition of the pool (array 3). Here is what the 3 dimensional version looks like:
$soapClient->create(array('hostname'), array(3), array(array(array('pool_name' => 'hostname-pool01', 'order' => 1, 'ratio' => 1))), array(array(array('rule_name' => 'name1', 'priority' => 1))));
And the soap request that gets generated:
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns2="urn:iControl" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
hostname
3
hostname-pool01
1
1
name1
1
Theres our data! Based on what the soap request generates we can see that what its looking for is an array for the WideIPPoolSequence, then an array for the WideIPPool, finally the array that defines the pool data. Hopefully this will help out others who are using PHP and iControl through soap.
One more thing, common symptons:
1st. If you use a 1 dimensional array the request will actually go through without an error, however the changes you try to make will not occur (saw this in a couple of threads).
2nd. Like the dev's have said if you get the error message 'Could not find element by name:' it means your request is packaged wrong. Make sure your using the correct number of array dimensions.
Credit for this goes to ogali (http://devcentral.f5.com/Default.aspx?tabid=53&forumid=1&tpage=1&view=topic&postid=1181411859) for putting me on the path to 3 dimensional arrays.
No RepliesBe the first to reply
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects