This is the Ismo_Core_Object_Plain superclass, you should subclass your own classes from this one.
This is class is here to make life easy for you, as most of ismo is. By subclassing from this class you get quite many nice benefits:
Located in /Object/Plain.php (line 83)
An array containing a list errors resulting from the validate() method
This array will be populated by the validate() method by setting the key to the attribute name, and the value to the error returned by the specify validate method. You can then use these in the template engine to either show errors for a specific field or iterate thru the array to show the list of errors in the data to be validated.
Example:
This sets the $mo attributes from the $_POST variables and calls the validate methods that have been defined. If validate() returns false we dump the $errors array with the errors our validate methods produced.
An array containing a list of all the private attributes' names.
The attributes named in this array won't be exposed to the template engine. It might for example be wise to not expose a user's real password to the templates.
Example:
- $_private = array("id", "user_information_id");
This specifies that id and user_information_id are private attributes.
The constructor.
It is possible to pass in either an array or an Ismo_Core_Object_Plain and if so setFrom() is called with that parameter.
Returns an array representation of the class's attributes.
Returns the class's attributes in an associative array, with the attribute's name as key and the value as the value. This if useful for example when exposing the object to the template engine.
The attribute listed in the _private array are not included.
Note: In versions prior to PHP 4.2.0, if the variables declared in the class of which the obj is an instance, have not been assigned a value, those will not be returned in the array. In versions after PHP 4.2.0, the key will be assigned with a NULL value.
Example:
This results in $hash being an array containing the key-value pairs of the attributes that have a value. It will containg the following "name" => "name" and "phone_no" => "034-34343".
- $p = new Person();
- $p->name = "name";
- $p->phone_no = "034-34343";
- $hash = $p->getArrayRepresentation();
Tries to "fill" in the current object from the array or objects given as parameter.
This method updates the current object with the values available in the given Ismo_Core_Object or array. Note that attributes listed in the _private attribute are not updated.
Example:
This sets $p's name attribute to 'Ismo' and phone_no to '456'.
- $p = new Person();
- $a = array("name" => "Ismo", "phone_no" => "456");
- $p->setFrom($a);
- $p1 = new Person();
- $p1->id = 1;
- $p1->name = "name1";
- $p1->phone_no = "name2";
- $p2 = new Person();
- $p2->id = 2;
- $p2->setFrom($p1);
This sets $p2's name and phone_no attributes to the same as in p1. But the id attributes will still be different.
Validates this object.
The validation is done by calling a method named validate[class attribute name] for each class attribute. If the method doesn't exist no validation will be done for that attribute.
Any amount of parameters can be given to this method. All paramters given will be given to each of the validate methods when they are called. If the amount of parameters do not match you will get a PHP error.
Please note that the attribute's mentioned in the _private attribute, i.e. the private attributes, won't be validated.
By using require_once() to include PEAR's Validate class in a validate methode one can use those functions to validate the data.
Example:
This will validate the attribute values of the Person class instance by calling the validateName(), validatePhoneNo() and validateCountry() methods if they exist.
Another example showing how the multiple parameters work:
- class Foo extends Ismo_Core_Object
- {
- var $name;
- var $address;
- function Foo($src = null)
- {
- parent::Ismo_Core_Object($src);
- }
- function validateName($country, $language)
- {
- if ($country == 'sweden' &&
- $language == 'swedish')
- {
- // do swedish check ...
- }
- else if ($country == 'finland' &&
- $language == 'finnish')
- {
- // do finnish check ...
- }
- else
- {
- // do other check
- }
- }
- // and similar other validate methods
- }
- // now when validating Foo objects one has to give a
- // country and language. Of course those attributes could
- // have been assigned default values, i.e.
- // function validate_name($country = null, $language = null)
- $a = new Foo();
- if ($a->validate('sweden', 'swedish') != true)
- {
- foreach ($a->errors as $k => $v)
- {
- echo "Attribute " . $k . " isn't valid due to " . $v . "<br/>";
- }
- }
Creates the setter method name for a given attribute.
Given the attribute name this method returns the name of the setter method which can be used to set the value of the attribute.
Documentation generated on Mon, 14 Jun 2004 11:59:30 +0200 by phpDocumentor 1.3.0RC3