In my controller I have a function than set IP to entity:
$inventory = new Inventory();
$inventory->setIp($xml->COMPUTER->IP);
but $xml->COMPUTER->IP
have two values. When I run:
foreach($xmlOcs->COMPUTER as $ips){
echo $ips->IPADDRESS;
}
the two values are shown!
My question is, how can I set to entity ( $ip
) the two values?
My entity:
private $ipaddress = array();
public function setIpAddress($ipaddress) {
$this->ipaddress = $ipaddress;
return $this;
}
public function getIpAddress() {
return $this->ipaddress;
}
Based on your example, this can easily be done if you use array empty key assignment :
foreach($xmlOcs->COMPUTER as $ips){
$inventory->addIpAddress($ips->IPADDRESS);
}
private $ipaddress = array();
public function addIpAddress($ipaddress) {
$this->ipaddress[] = $ipaddress;
return $this;
}
public function getIpAddress() {
return $this->ipaddress;
}
However this has nothing to do with Symfony, it is pure very basic php.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.