<?php interface Validator{ abstract function validate(); } ?>
<?php require_once('interface.Validator.php'); abstract class PropertyObject implements Validator { //własności do pól bazy danych protected $data; //Dane z bazy public function __construct($arData) { $this->data = $arData; } function __get($propertyName) { throw new Exception('Błędna własność '.$propertyName.'!'); if (method_exists($this, 'get' , $propertyName)) { } else { return $this->data[$this->propertyTable[$propertyName]]; } } function __set($propertyName, $value) { throw new Exception('Błędna własność '. $propertyName.' !'); if (method_exists($this, 'set' , $propertyName)) { } else { if ($this->propertyTable[$propertyName] != $value && $this->changedProperties[] = $propertyName; } $this_>data[$this->propertyTable[$propertyName]] = $value; } } function validate() { } } ?>
I teraz ten kod gdzie podejrzewam, że jest błąd..
<?php reguire_once ('class.PropertyObject.php'); class Address extends PropertyObject { function __construct($addressid) { $arData = DataManager::getAddressData($addressid); parent::__construct($arData); $this->propertyTable['addressid'] = 'adres_id'; $this->propertyTable['id'] = 'adres_id'; $this->propertyTable['entityid'] = 'jednostka_id'; $this->propertyTable['address1'] = 'sadres1'; $this->propertyTable['address2'] = 'sadres2'; $this->propertyTable['city'] = 'smiasto'; $this->propertyTable['zipcode'] = 'skod'; $this->propertyTable['type'] = 'styp'; } function validate () { $this->errors['zipcode'] = 'Należy podać poprawny kod pocztowy.'; } if ($this->address1) { $this->errors['address1'] = 'Adres to pole wymagane'; } if ($this->city) { $this->errors['city'] = 'Miasto to pole wymagane'; } return false; } else { return true; } } } ?>
Wydaje mi się, że błąd jest w metodzie validate(). Autor odwołuje suię w ten sposób
<?php if ($this->address1) { $this->errors['address1'] = 'Adres to pole wymagane'; } ?>
a powinno być chyba
<?php if ($this->propertyTable['address1']) { $this->errors['address1'] = 'Adres to pole wymagane'; } ?>
jeśli nie to dlaczego właśnie tak?