# Key Classes

## Key Classes/Objects API

**Using Xoops API**

In addition to the Xoops API documentation <http://api.xoops.org/> here we also need guidelines for module writers as to what classes to use when, why, and how, etc. For example:

* XoopsObject Data Access classes

If you create a module class (in the class folder of your module) called `Myclass` that extends `XoopsObject`:

```php
<?php

namespace XoopsModules\Mymodule;

class Myclass extends \XoopsObject
{
    /**
    * Constructor
    **/
    public function __construct() // Constructor
    {
    $this->initVar('my_variable', XOBJ_DTYPE_INT, NULL);
    }
}
```

In a separate file we create a handler called `MyclassHandler` that extends XoopsPersistableObjectHandler:

```php
<?php

namespace XoopsModules\Mymodule;

class MyclassHandler extends \XoopsPersistableObjectHandler
   {
   }
```

you can then obtain a reference to an instance of the handler class like this: In /modules/module/index.php:

```php
<?php

namespace XoopsModules\Mymodule;

$myclassHandler = new Mymodule\MyclassHandler();
```

Built in data object handlers can be obtained via xoops\_gethandler(''). Search for the use of this idiom in other modules for an idea of how these classes let you build data access objects to interface with corresponding database tables.

![](/files/-M5aqYwKVhpcf3UiCMZM)

![](/files/-M5aqYwM4_aRUSVinGVN)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://xoops.gitbook.io/xoops-modules-cookbook/core-classes/core/key-classes.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
