We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34084 ☆ A M B ☆
    • 756 Posts
    Hello all,

    I’ve been working on this for a few days, and I know it’s going to be something stupidly simple, but I’m not having any luck getting the tables to generate with xPDO. I have the build script that creates the class files based on the schema xml doc which works just fine. Then when I run the snippet to build the tables for the first run through i get some log messages in the /core/cache/logs/error.log file:

    [2011-07-05 11:17:49] (ERROR @ /modxrevo/index.php) Could not get table name for class: awdbio
    [2011-07-05 11:17:49] (ERROR @ /modxrevo/index.php) Could not load class: awdbios from mysql.awdbios.
    


    here is my snippet that is running this:

    <?php
    $awdbios = $modx->getService('awdbios','awdbio',$modx->getOption('awdbios.core_path',null,$modx->getOption('core_path').'components/awdbios/').'model/awdbios/',$scriptProperties);
    if (!($awdbios instanceof awdbio))
        return '<br />NO instance of Awdbios.<br />';
    
    if(! $awdbios){
        $modx->log(modX::LOG_LEVEL_ERROR,'awdbios: package/service not found!');
        return '<br />awdbios: package/service not found!';
    }
    
    //-- Setup the default properties
    $tpl = $modx->getOption('tpl',$scriptProperties,'rowTpl');
    $sort = $modx->getOption('sort',$scriptProperties,'name');
    $dir = $modx->getOption('dir',$scriptProperties,'ASC');
    
    $output = '';
    
    $m = $modx->getManager();
    $m->createObjectContainer('awdbios');
    return '<br />Table created.';
    
    return $output;
    ?>
    


    the mysql.schema.xml file:
    <?xml version="1.0" encoding="UTF-8"?>
    <model package="awdbios" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" phpdoc-package="awdbios" phpdoc-subpackage="model">
        <object class="awdbio" table="awdbios_member" extends="xPDOSimpleObject">
            <field key="fname" dbtype="varchar" phptype="255" null="false" default=""/>
            <field key="lname" dbtype="varchar" precision="255" null="false" default=""/>
            <field key="mi" dbtype="varchar" precision="1" null="true" default=""/>
            <field key="email" dbtype="varchar" precision="255" null="false" default=""/>
            <field key="phone" dbtype="varchar" precision="20" null="true" default=""/>
            <field key="mobile" dbtype="varchar" precision="20" null="true" default=""/>
            <field key="fax" dbtype="varchar" precision="20" null="true" default=""/>
            <field key="title" dbtype="varchar" precision="255" null="true" default=""/>
            <field key="address" dbtype="varchar" precision="255" null="true" default=""/>
            <field key="addressalt" dbtype="varchar" precision="255" null="true" default=""/>
            <field key="city" dbtype="varchar" precision="255" null="true" default=""/>
            <field key="state" dbtype="varchar" precision="255" null="true" default=""/>
            <field key="zip" dbtype="varchar" precision="10" null="true" default=""/>
            <field key="photo" dbtype="varchar" precision="255" null="true" default=""/>
            <field key="biography" dbtype="text" phptype="string" null="true" default=""/>
            <field key="active" 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="CreatedBy" class="modUser" local="createdby" foreign="id" cardinality="one" owner="foreign"/>
            <aggregate alias="EditedBy" class="modUser" local="editedby" foreign="id" cardinality="one" owner="foreign"/>
        </object>
    </model>
    


    Any points, as I’m running up on a deadline and it’s driving me crazy... smiley thanks in advance for your help.

    Cheers
      Evo Revo // Ubuntu, CentOS, Win // Apache 2x, Lighttp (Lighty)
      Visit CharlesMx.com for latest news and status updates.
      • 33968
      • 863 Posts
      How about:
      $m->createObjectContainer('awdbio');   // remove the 's' to match your object class
      return '<br />Table created.';
      
      return $output;
      ?>
      
        • 34084 ☆ A M B ☆
        • 756 Posts
        tried that many times, making sure that my naming matched but doesn’t make a difference:

        Script Error:
        FastCGI-stderr: PHP Fatal error:  Class 'awdbio_mysql' not found in /var/www/modxrevo/core/xpdo/xpdo.class.php on line 602


        /core/cache/logs/error.log
         [2011-07-05 15:30:24] (ERROR @ /modxrevo/index.php) Could not get table name for class: awdbio
        
          Evo Revo // Ubuntu, CentOS, Win // Apache 2x, Lighttp (Lighty)
          Visit CharlesMx.com for latest news and status updates.
          • 33968
          • 863 Posts
          If you’ve changed your schema at all since running your build script you will need to delete those generated class files and run the script again. Caught me out a few times!

          Otherwise check all those files and see if they contain the correct tables, class names and paths. Actually if I were you, I’d delete the above anyway and run the script again. I’d also capitalise your class name in the schema (and in your snippet code) just to make it easier to read:

          [tt]<model package="awdbios" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" phpdoc-package="awdbios" phpdoc-subpackage="model">
          <object class="Awdbio" table="awdbios_member" extends="xPDOSimpleObject">[/tt]


            • 34084 ☆ A M B ☆
            • 756 Posts
            agreed, and that was the last round that I tried lower case just to see if it was capitalization issue on the server/class name. I’ll run it back through again.

            I’ve also noticed that my class file mxbio.class.php only has

            <?php
            require_once (dirname(dirname(__FILE__)) . '/mxbio.class.php');
            class mxBio_mysql extends mxBio {}


            renaming the schema class name now and will rerun the builder.
              Evo Revo // Ubuntu, CentOS, Win // Apache 2x, Lighttp (Lighty)
              Visit CharlesMx.com for latest news and status updates.
              • 34084 ☆ A M B ☆
              • 756 Posts
              Now my error is only this inside the /core/cache/logs/error.log file:

              [2011-07-06 10:39:16] (ERROR @ /modxrevo/index.php) Could not get table name for class: Awdbio


                Evo Revo // Ubuntu, CentOS, Win // Apache 2x, Lighttp (Lighty)
                Visit CharlesMx.com for latest news and status updates.
                • 10487 MODX Staff
                • 1,535 Posts
                The error is because you’ve changed the capitalization on the class name in the schema.

                Delete your awdbio.class.php in your model directory and then regenerate your model from the schema - this will allow the class file to be created with the correct class name.
                  Garry Nutting
                  Senior Developer
                  MODX, LLC

                  Email: [email protected]
                  Twitter: @garryn
                  Web: modx.com
                  • 34084 ☆ A M B ☆
                  • 756 Posts
                  I did, sorry should have reposted that before. I changed the schema file to the following:

                  <?xml version="1.0" encoding="UTF-8"?>
                  <model package="awdbios" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" phpdoc-package="awdbios" phpdoc-subpackage="model">
                      <object class="Awdbio" table="awdbios_member" extends="xPDOSimpleObject">
                          <field key="fname" dbtype="varchar" phptype="255" null="false" default=""/>
                          <field key="lname" dbtype="varchar" precision="255" null="false" default=""/>
                          <field key="mi" dbtype="varchar" precision="1" null="true" default=""/>
                          <field key="email" dbtype="varchar" precision="255" null="false" default=""/>
                          <field key="phone" dbtype="varchar" precision="20" null="true" default=""/>
                          <field key="mobile" dbtype="varchar" precision="20" null="true" default=""/>
                          <field key="fax" dbtype="varchar" precision="20" null="true" default=""/>
                          <field key="title" dbtype="varchar" precision="255" null="true" default=""/>
                          <field key="address" dbtype="varchar" precision="255" null="true" default=""/>
                          <field key="addressalt" dbtype="varchar" precision="255" null="true" default=""/>
                          <field key="city" dbtype="varchar" precision="255" null="true" default=""/>
                          <field key="state" dbtype="varchar" precision="255" null="true" default=""/>
                          <field key="zip" dbtype="varchar" precision="10" null="true" default=""/>
                          <field key="photo" dbtype="varchar" precision="255" null="true" default=""/>
                          <field key="biography" dbtype="text" phptype="string" null="true" default=""/>
                          <field key="active" 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="CreatedBy" class="modUser" local="createdby" foreign="id" cardinality="one" owner="foreign"/>
                          <aggregate alias="EditedBy" class="modUser" local="editedby" foreign="id" cardinality="one" owner="foreign"/>
                      </object>
                  </model>
                  


                  the class file outside the mysql folder (/core/components/awdbios/model/awdbios/awdbio.class.php) contains the following:
                  <?php
                  class Awdbio extends xPDOSimpleObject {}


                  then the class file in the .../mysql/awdbio.class.php contains:
                  <?php
                  require_once (dirname(dirname(__FILE__)) . '/awdbio.class.php');
                  class Awdbio_mysql extends Awdbio {}


                  The tables are not being created by the snippet and the only error I get back is the one previously mentioned in the cache error.log.

                  Here is the code in my snippet:

                  <?php
                  
                  //-- Short Hand
                  $awdbios = $modx->getService('awdbios','Awdbio',$modx->getOption('awdbios.core_path',null,$modx->getOption('core_path').'components/awdbios/').'model/awdbios/',$scriptProperties);
                  if (!($awdbios instanceof awdbio))
                      return '<br />NO instance of Awdbios.<br />';
                  
                  //-- Setup the default properties
                  $tpl = $modx->getOption('tpl',$scriptProperties,'rowTpl');
                  $sort = $modx->getOption('sort',$scriptProperties,'name');
                  $dir = $modx->getOption('dir',$scriptProperties,'ASC');
                  
                  $output = '';
                  $base_path = !empty($base_path) ? $base_path : $modx->getOption('core_path').'components/awdbios/';
                  $modx->addPackage('awdbios',$base_path.'model/');
                  
                  
                  $m = $modx->getManager();
                  $m->createObjectContainer('Awdbio');
                  
                  return '<br />Table created.';
                  
                  
                  return $output;
                  ?>


                  This might help, I’ve attached a zip file of all the files associated to the package.

                  Cheers
                    Evo Revo // Ubuntu, CentOS, Win // Apache 2x, Lighttp (Lighty)
                    Visit CharlesMx.com for latest news and status updates.
                    • 34084 ☆ A M B ☆
                    • 756 Posts
                    something even more sinister is going on in the class build of the xPDO as when I download the example by splittingred and just run the build script the class file is not fully created they are only partially created.

                    Example: the file from the zip file for Doodles
                    <?php
                    class Doodle extends xPDOSimpleObject {
                        public function __construct(& $xpdo) {
                            parent :: __construct($xpdo);
                        }
                    
                        /**
                         * Overrides xPDOObject::save to add edited/created auto-filling fields
                         *
                         * {@inheritDoc}
                         */
                        public function save($cacheFlag = null) {
                            /* set createdon/editedon */
                            $now = new DateTime();
                            $type = $this->isNew() ? 'created' : 'edited';
                            $this->set($type.'on',$now->format('Y-m-d h:i:s'));
                            if ($this->xpdo instanceof modX && $this->xpdo->user) {
                                $this->set($type.'by',$this->xpdo->user->get('id'));
                            }
                    
                            return parent :: save($cacheFlag);
                        }
                    }


                    then after I run the build script on my machine:
                    <?php
                    class Doodle extends xPDOSimpleObject {}



                      Evo Revo // Ubuntu, CentOS, Win // Apache 2x, Lighttp (Lighty)
                      Visit CharlesMx.com for latest news and status updates.
                      • 34084 ☆ A M B ☆
                      • 756 Posts
                      Anyone have any thoughts or suggestions as to why the build scripts would not make a full xpdo class file as noted above?

                      thanks again for everyone for your suggestions.

                      Cheers
                        Evo Revo // Ubuntu, CentOS, Win // Apache 2x, Lighttp (Lighty)
                        Visit CharlesMx.com for latest news and status updates.