We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10152
    • 156 Posts
    Hello, strange problem today, custom tables are not created.

    MODX Revolution 2.1.3-pl (traditional).
    DB version : 5.1.54-1ubuntu4

    Here is how I proceed :

    1 ) create .php files and folder hierarchy (00.png)
    2 ) after running build.schema.php, new files are created (01.png)
    3 ) when running snippet.storefinder.php the tables are not created :
    <?php
    /**
     * @package storefinder
     */
    $base_path = !empty($base_path) ? $base_path : $modx->getOption('core_path').'components/storefinder/';
    $modx->addPackage('storefinder',$base_path.'model/');
    
    $store = $modx->newObject('sfStore');
    $store->fromArray(array(
        'name' => 'Store 1',
        'address' => '12 Grimmauld Place',
        'city' => 'London',
        'country' => 'England',
        'zip' => '12345',
        'phone' => '555-2134-543',
    ));
    $store->save();
     
    $store = $modx->newObject('sfStore');
    $store->fromArray(array(
        'name' => 'Store 2',
        'address' => '4 Privet Drive',
        'city' => 'London',
        'country' => 'England',
        'zip' => '53491',
        'phone' => '555-2011-978',
    ));
    $store->save();
    
    $stores = $modx->getCollection('sfStore');
    echo 'Total: '.count($stores);
    

    Xml file :
    <?xml version="1.0" encoding="UTF-8"?>
    <model package="storefinder" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" phpdoc-package="storefinder" phpdoc-subpackage="model">
    <object class="sfStore" table="sfinder_stores" extends="xPDOSimpleObject">
    <field key="name" dbtype="varchar" precision="100" phptype="string" null="false" default="" index="index"/>
    <field key="address" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
    <field key="city" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
    <field key="state" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
    <field key="zip" dbtype="varchar" precision="10" phptype="string" null="false" default="0" index="index"/>
    <field key="country" dbtype="varchar" precision="20" phptype="string" null="false" default=""/>
    <field key="phone" dbtype="varchar" precision="20" phptype="string" null="false" default=""/>
    <field key="fax" dbtype="varchar" precision="20" phptype="string" null="false" default=""/>
    </object>
    </model>
    
      • 33968
      • 863 Posts
      I use this little snippet to create a new table once the schema is set up, see if that works for you:
      <?php
      $table = 'sfStore';
      $m = $modx->getManager();
      $created = $m->createObjectContainer($table);
      return $created ? "Table created: $table" : "Table not created: $table";
      
        • 10152
        • 156 Posts
        table not created
          • 33968
          • 863 Posts
          Did you include the model path?

          $base_path = !empty($base_path) ? $base_path : $modx->getOption('core_path').'components/storefinder/';
          $modx->addPackage('storefinder',$base_path.'model/');
          
            • 10152
            • 156 Posts
            it works. thanks