# MODX 3 custom tables 'class not found' \[Solved\]

**URL:** <https://community.modx.com/t/modx-3-custom-tables-class-not-found-solved/5329>\
**Category:** Development\
**Created:** [May 10, 2022, 8:50am UTC](https://community.modx.com/t/modx-3-custom-tables-class-not-found-solved/5329 "2022-05-10T08:50:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![culd\_steffan](https://community.modx.com/user_avatar/community.modx.com/culd_steffan/32/2999_2.png) [@culd\_steffan](https://community.modx.com/u/culd_steffan)\
**Post date:** [May 10, 2022, 8:50am UTC](https://community.modx.com/t/modx-3-custom-tables-class-not-found-solved/5329/1 "2022-05-10T08:50:49Z")

</div>

Hi,  
I’m currently adding custom tables to MODX 3 which seems to be a bit different than with MODX 2. according to [Using Custom Database Tables - Tutorials | MODX Documentation](https://docs.modx.com/3.x/en/extending-modx/tutorials/using-custom-database-tables)

I’ve adjusted the folders/locations accordingly and I’ve changed the xml schema with namespaces etc. When building the Schema, the Modal folder is added to the src folder with all classes in it, so that seems to be ok. But it looks like the namespace is not adding the classname.  
Below the cdbTeam.php file from the Model dir. In the docs it says the namespace should be something like ‘namespace CustomDatabase\Model\cdbTeam’

```auto
<?php
namespace CustomDatabase\Model;

use xPDO\xPDO;

/**
 * Class cdbTeam
 *
 * @property string $naam
 * @property string $teamtype
 * @property float $lat
 * @property float $lng
 * @property integer $radius
 * @property integer $aantal_bomen
 * @property integer $landschap_id
 * @property string $createdon
 * @property integer $createdby
 * @property string $editedon
 * @property integer $editedby
 *
 * @package CustomDatabase\Model
 */
class cdbTeam extends \xPDO\Om\xPDOSimpleObject
{
}

```

When I try to create the tables I get an error that the classes don’t exist.  
(class\_exists(“Customdatabase\Model\cdbTeam”) always returns ‘false’.

Any ideas?

If needed, the xml begins like this:

```auto
<?xml version="1.0" encoding="utf-8"?>
<model package="CustomDatabase\Model" baseClass="xPDO\Om\xPDOObject" platform="mysql" defaultEngine="MyISAM" version="3.0">
	
	
	<!-- TABEL cdbTeam -->
	<object class="cdbTeam" table="cdb_team" extends="xPDO\Om\xPDOSimpleObject">
		<field key="naam" dbtype="varchar" precision="100" phptype="string" null="true" default="" />
		<field key="teamtype" dbtype="varchar" precision="100" phptype="string" null="true" default="vast" /><!--vast/flexibel-->
		
		<field key="lat" dbtype="float" precision="16,14" phptype="float" null="true" default="" />
		<field key="lng" dbtype="float" precision="16,14" phptype="float" null="true" default="" />	
		
		<field key="radius" dbtype="int" precision="1" phptype="integer" null="false" default="5" /><!--kms rond locatie-->
		<field key="aantal_bomen" dbtype="int" precision="1" phptype="integer" null="false" default="5" />
		<field key="landschap_id" dbtype="int" precision="1" phptype="integer" null="false" default="0" />
		
		
		<field key="createdon" dbtype="datetime" phptype="datetime" null="true"/>
		<field key="createdby" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" />
		<field key="editedon" dbtype="datetime" phptype="datetime" null="true"/>
		<field key="editedby" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" />
		
		<aggregate alias="Landschap " class="CustomDatabase\Model\cdbLandschap" local="landschap_id" foreign="id" cardinality="one" owner="foreign"/>
		
		<aggregate alias="CreatedBy " class="MODX\Revolution\modUser" local="createdby" foreign="id" cardinality="one" owner="foreign"/>
		<aggregate alias="EditedBy " class="MODX\Revolution\modUser" local="editedby" foreign="id" cardinality="one" owner="foreign"/>
	</object>

```

---

<div class="post-metadata">

**Author:** ![halftrainedharry](https://community.modx.com/user_avatar/community.modx.com/halftrainedharry/32/1063_2.png) [@halftrainedharry](https://community.modx.com/u/halftrainedharry)\
**Post date:** [May 10, 2022, 9:29am UTC](https://community.modx.com/t/modx-3-custom-tables-class-not-found-solved/5329/2 "2022-05-10T09:29:16Z")

</div>

> [@culd\_steffan](#):
>
> But it looks like the namespace is not adding the classname.  
> Below the cdbTeam.php file from the Model dir. In the docs it says the namespace should be something like ‘namespace CustomDatabase\Model\cdbTeam’

No, I think it is correct the way it is now.

* * *

How exactly do you try to create the tables?  
Do you call `$modx->addPackage()` for your model before executing `createObjectContainer()`?  
Or do you have a `bootstrap.php` file that calls `$modx->addPackage()`?

* * *

If you can’t make it work, then maybe use the extra _ExtraBuilder_ instead.

[https://modx.com/extras/package/extrabuilder](https://modx.com/extras/package/extrabuilder)

---

<div class="post-metadata">

**Author:** ![culd\_steffan](https://community.modx.com/user_avatar/community.modx.com/culd_steffan/32/2999_2.png) [@culd\_steffan](https://community.modx.com/u/culd_steffan)\
**Post date:** [May 10, 2022, 9:42am UTC](https://community.modx.com/t/modx-3-custom-tables-class-not-found-solved/5329/3 "2022-05-10T09:42:06Z")

</div>

Thanks for the reply.

I’ll have a look at the extrabuilder, but I’d like to know how it works because I have a couple of websites with custom tables that need to be updated to MODX 3.

The addPackage() is called in the bootstrap.php indeed:

```auto
$modx->addPackage('CustomDatabase\Model', $namespace['path'] . 'src/', null, 'CustomDatabase\\');

```

The error log is empty, so it’s hard to tell what’s going wrong.

---

<div class="post-metadata">

**Author:** ![culd\_steffan](https://community.modx.com/user_avatar/community.modx.com/culd_steffan/32/2999_2.png) [@culd\_steffan](https://community.modx.com/u/culd_steffan)\
**Post date:** [May 10, 2022, 11:13am UTC](https://community.modx.com/t/modx-3-custom-tables-class-not-found-solved/5329/4 "2022-05-10T11:13:59Z")

</div>

Found out what was wrong, typo 😒

“Customdatabase\Model\cdbTeam” had to be “CustomDatabase\Model\cdbTeam”

---

<div class="post-metadata">

**Author:** ![bobray](https://community.modx.com/user_avatar/community.modx.com/bobray/32/46_2.png) [@bobray](https://community.modx.com/u/bobray)\
**Post date:** [May 11, 2022, 11:24pm UTC](https://community.modx.com/t/modx-3-custom-tables-class-not-found-solved/5329/5 "2022-05-11T23:24:16Z")

</div>

I find the PhpStorm editor helpful in these kind of situations. Other good code editors may be as well.

MODX 3 is a project in PhpStorm and I have a little Fiddle.php file for testing things.

I put in code like this:

```auto
class MyClass extends {
}

```

When I change it to:

```auto
class MyClass extends MODX\Revolution\ {
}

```

When I type the final `\`, PhpStorm shows me a list of the classes that could come next. The continues for subsequent backslashes.

It’s a little funky sometimes because of the complexity of the project and MODX’s aliases, but it usually works. At times, it’s the only way I’ve been able to come up with a working fully qualified class name like the one for this processor:

`MODX\Revolution\Processors\System\Dashboard\Widget\Remove`
