# XoopsObject

## Definition

**XoopsObject** is an Abstract class, a base class for all objects in the Xoops kernel (and beyond)

![](https://879096944-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M5_mFcvcxsA3M1QhbWd%2F-M5aqXyEhtReBwxHT9Gi%2F-M5aqYwKVhpcf3UiCMZM%2FXoopsObject.png?generation=1587642255190457\&alt=media)

## Usage

XoopsObject should be handled as an abstract class and has the following useful functions:

* **initVar($key,$data\_type,$value,$required,$maxlength,$options)** :  initialize a variable. Use this, when extending XoopsObject instead of declaring variables the normal way. for $data\_type, see below. $options is string for select options   &#x20;
* **getVar($key,$format)** - retrieves an object variable ($format is 's' for display on page, 'f' for form info, or 'n' for no cleaning.
* **getVars()** - retrieves array of key=>value pairs
* **cleanVars()** - "cleans" the object variables, which have changed, according to their type set in initVar()
* **clone()** - create a clone(copy) of the current object
* **setVar($key,$value,$not\_gpc)** - assign a value $value to a variable $key; sets object dirty
* **setVars($var\_array)** - assign values to variables from a key=>value pair array; sets object dirty
* **assignVar($key,$value)** - assign a value to a variable
* **assignVars($var\_array)** - assign values to variables from a key => value pair array

The last two functions are for new(-ly instantiated) objects. For existing objects, which are subsequently modified, you should use setVar() and setVars() - this will set the object status to "dirty" i.e. that it has been modified and variable values not sanitized.

Data Types (for initVar function above):

* XOBJ\_DTYPE\_TXTBOX - Text Box
* XOBJ\_DTYPE\_TXTAREA - Text Area
* XOBJ\_DTYPE\_INT - Integer
* XOBJ\_DTYPE\_URL - URLs
* XOBJ\_DTYPE\_EMAIL - E-mails
* XOBJ\_DTYPE\_ARRAY - Arrays
* XOBJ\_DTYPE\_OTHER - Others (won't be cleaned)
* XOBJ\_DTYPE\_SOURCE -
* XOBJ\_DTYPE\_STIME - Short Time
* XOBJ\_DTYPE\_MTIME - Medium Time
* XOBJ\_DTYPE\_LTIME - Long Time\*\*

Note Don't give, to a field's name of your table, the table's name or you will have a problem in the XoopsObject class while saving the datas
