I have a error saying that,
Fatal error: Call to a member function getId() on null.
but how can i check the element, here is my code
$infoArray['groupId'] = $info->getId();
$infoArray['name'] = $info->getName();
$infoArray['addressLine1'] = $info->getAddressLine1();
$infoArray['addressLine2'] = $info->getAddressLine2();
$infoArray['isActive'] = $info->getActive();
$infoArray['countryId'] = $info->getCountry()->getId(); //Here is my error line
$infoArray['countryName'] = $info->getCountry()->getName();
$infoArray['stateId'] = $info->getState()->getId();
$infoArray['stateName'] = $info->getState()->getName();
$infoArray['cityId'] = $info->getCity()->getId();
$infoArray['cityName'] = $info->getCity()->getName();
$infoArray['areaId'] = $info->getArea()->getId();
$infoArray['areaName'] = $info->getArea()->getName();
$infoArray['zipcode'] = $info->getZipcode();
Replace the line by :
$infoArray['countryId'] = $info->getCountry() ? $info->getCountry()->getId() : null;
Do the same for each line corresponding to an association (which can be null), and null will be returned if the object is null.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With