We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25586
    • 105 Posts
    Hi fellow modx lovers!

    I installed a clean install of modx revolution 2.1-rc3 and followed the tutorial ’Developing an Extra in MODX Revolution’ like I normally do.

    I created the schema file and added my snippet, but now I receive the following error:

    [2011-04-23 00:03:27] (ERROR @ /index.php) Error 42S02 executing statement: 
    Array
    (
        [0] => 42S02
        [1] => 1146
        [2] => Table 'sandbox.modx_sandbox' doesn't exist
    )
    
    


    I have the same problem on my webserver and my mamp server. How can I fix this?

    My schema looks like this:
    <?xml version="1.0" encoding="UTF-8"?>
    <model package="sandbox" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM">
    
      <object class="Sandbox" table="sandbox" extends="xPDOSimpleObject">
    	<field key="name" dbtype="varchar" precision="100" phptype="string" null="false" default="" />
    	<field key="email" dbtype="varchar" precision="100" phptype="string" null="false" default="" />
    	<field key="website" dbtype="varchar" precision="100" phptype="string" null="false" default="" />
      </object>
      
    </model>
    


    It looks like the table is not getting created, normally this would happen if the user requests/adds something from/to the database.

    I hope someone can help me out.

    Regards,

    Rogier
      • 3749
      • 24,544 Posts
      Did you run parseSchema() after creating the schema? That’s required to create the classes and class maps for xPDO.

      There’s some info here that might help: http://bobsguides.com/custom-db-tables.html
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 25586
        • 105 Posts
        Yeah I did,

        I have all the files in the model directory. here is my snippet cal the the Sandbox class:
        $sandbox = $modx->getService('sandbox','Sandbox',$modx->getOption('sandbox.core_path',null,$modx->getOption('core_path').'components/sandbox/').'model/sandbox/',$scriptProperties);
        if (!($sandbox instanceof Sandbox)) return '';


        And this is my sandbox.class.php
        <?php
        class Sandbox {
        
        	public $modx;
        	public $config = array();
        	
        	function __construct(modX &$modx,array $config = array()) {
        	
        		$this->modx =& $modx;
        
                $basePath = $this->modx->getOption('sandbox.core_path',$config,$this->modx->getOption('core_path').'components/sandbox/');
                $assetsUrl = $this->modx->getOption('sandbox.assets_url',$config,$this->modx->getOption('assets_url').'components/sandbox/');
                $this->config = array_merge(array(
                    'basePath' => $basePath,
                    'corePath' => $basePath,
                    'modelPath' => $basePath.'model/',
                    'processorsPath' => $basePath.'processors/',
                    'chunksPath' => $basePath.'elements/chunks/',
                    'jsUrl' => $assetsUrl.'js/',
                    'cssUrl' => $assetsUrl.'css/',
                    'assetsUrl' => $assetsUrl,
                    'connectorUrl' => $assetsUrl.'connector.php',
                ),$config);
        
                $this->modx->addPackage('sandbox',$this->config['modelPath']);
            }
        
            public function getChunk($name,$properties = array()) {
                $chunk = null;
                if (!isset($this->chunks[$name])) {
                    $chunk = $this->_getTplChunk($name);
                    if (empty($chunk)) {
                        $chunk = $this->modx->getObject('modChunk',array('name' => $name));
                        if ($chunk == false) return false;
                    }
                    $this->chunks[$name] = $chunk->getContent();
                } else {
                    $o = $this->chunks[$name];
                    $chunk = $this->modx->newObject('modChunk');
                    $chunk->setContent($o);
                }
                $chunk->setCacheable(false);
                return $chunk->process($properties);
            }
        
            private function _getTplChunk($name,$postfix = '.chunk.tpl') {
                $chunk = false;
                $f = $this->config['chunksPath'].strtolower($name).$postfix;
                if (file_exists($f)) {
                    $o = file_get_contents($f);
                    $chunk = $this->modx->newObject('modChunk');
                    $chunk->set('name',$name);
                    $chunk->setContent($o);
                }
                return $chunk;
            }
        }


        I tested if it is a instanceof, and it is. So I really don’t know why I have this error.

        ---- EDIT -----

        I can use the chunk function, so the class is working correct, I just wont create a table.

        Thanks so far
          • 3749
          • 24,544 Posts
          I’m not sure, but I think there may be a bug in xPDO or the feature of autocreating the table may have been removed. You may have to create the table yourself.

          You might try using addPackage() and loadClass() instead of getService().
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 25586
            • 105 Posts
            It is a bug, I found it in bugs.modx.com. It’s since rc3. Just have to create it manually then smiley

            Thanks!