new Country - jcobban/Genealogy GitHub Wiki
new Country($parms)
Up: class Country
The constructor for an instance of Country takes one parameter:
parameter | description |
---|---|
$parms | identifies the database record to be associated with this instance. This is an associative array. |
$parms may be:
- An associative array containing all of the fields in a record as obtained by a database SELECT.
array('code' => 'string')
specifies the unique ISO 3166-1 2-character code of the record in the table that is to be used to initialize the new instance. This unique key is used by other records in the database to link to this particular record.
If you wish to find an existing Country record by its name use:
$countries = new RecordSet(array('name' => 'America'));
$country = $countries->rewind(); // get first country in result
if ($country) // rewind may return false
print $country->getName();
In this example the RecordSet $countries contains all countries that contain the text 'America' in their names. On 6 Apr 2019 $country was set to "American Samoa" because that comes alphabetically before "United States of America".
The constructor throws an exception or adds error messages to $record->msg
if it is unable to complete due to bad parameters. If the ISO code does not correspond to any existing record the constructor completes but $country‑>isExisting()
returns false and $country->getName()
returns "Country: '$code'"
.
Next: $country->getName()