Create object on Modx3 using ExtrasBuilder

Hi, im trying a simple example using extrasBuilder and modx3 on a clean installation, this is my schema

<?xml version="1.0" encoding="UTF-8"?>
<model package="test" baseClass="xPDO\Om\xPDOObject" platform="mysql" defaultEngine="InnoDB" phpdoc-package="" version="3.0">
  <object class="modMyObject" table="modx_my_object" extends="xPDOObject">
    <field key="name" dbtype="varchar" precision="100" phptype="string" null="false" default=""/>
    <field key="address" dbtype="varchar" precision="100" phptype="string" null="false" default=""/>
  </object>
</model>

But when I try to build it, Im getting this error inside extraBuilder “Error, Validate ‘bootstrap.php’: Class still does not exist after autoloader registration: test\modMyObject”

and Could not load class: test\modMyObject from mysql.test\modmyobject On the MODX log

Also looking at the generated files, there only boilerplate code, but no trace of the table fields

What I’m missing?

I only use xPDO directly so not sure what pieces ExtrasBuilder may do for you magically, but what command did you use to build the schema? Are you providing your own PSR-4 autoloader (maybe EB does?) or are you relying on the one MODX registers when you do addPackage?

To be honest, at this stage I was more of a lookig for the “magical” solution, but seems like this would be a better path?

When it comes to stuff like this, I’ll just say I’m a big fan of understanding what’s going on under the hood before using magical stuff that makes it easier. In the end it should be running the same, just hidden behind a button or command, so knowing the command is a useful skill! :wink:

1 Like

ExtraBuilder expects a package name with \Model appended.

So if you change package="test" to package="test\Model" (and change extends="xPDOObject" to extends="xPDO\Om\xPDOObject") it should work.

<?xml version="1.0" encoding="UTF-8"?>
<model package="test\Model" baseClass="xPDO\Om\xPDOObject" platform="mysql" defaultEngine="InnoDB" phpdoc-package="" version="3.0">
  <object class="modMyObject" table="test_my_object" extends="xPDO\Om\xPDOObject">
    <field key="name" dbtype="varchar" precision="100" phptype="string" null="false" default=""/>
    <field key="address" dbtype="varchar" precision="100" phptype="string" null="false" default=""/>
  </object>
</model>
2 Likes

Thanks a lot, it did the trick!

This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.