Skip to content

Page::isValid

James Cobban edited this page Jun 23, 2021 · 5 revisions

$page->isValid()

Up: class Page

This method returns true if this instance represents a valid page within the enumeration division or sub-district, otherwise it returns false.

For most classes there is always a pre-defined record in the database if the record refers to a defined instance. So for most classes it is sufficient to call $record->isExisting() to validate that the constructor was called with parameters that identify the defined instance. However the class Page is different in that a record is only created in the database when it is required, since all of the information required to create a new instance of Page is defined in the containing instance of SubDistrict. For this reason instances of Page are most commonly created by calling $subdistrict->getPage($pagenum), which returns null if the page number is not supported. If the constructor for Page is explicitly invoked with an invalid page number it completes but $page->getErrors() returns a string containing an error message "Page::__construct: $page is not a valid page number within SubDistrict ($censusId,$distId,$sdId,$div). " and $page->isValid() returns false.

Given that $subdistrict is an instance of class SubDistrict you can either:

    $page      = $subdistrict->getPage($pagenum);
    if (is_null)
        $msg   = "$pagenum is not valid. ";

or

    $page      = new Page(array('sdid' => $subdistrict, 'pagenum' => $pageNum));
    if (!$page->isValid)
        $msg   = "$pagenum is not valid. " . $page->getErrors();

Next: $page->save()

Clone this wiki locally