We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32360
    • 16 Posts
    What i am trying to do:
    Interact with my extra table inside the database that modx use as well..

    My success and where i am failing
    I have an xampp installment. I use htdocs/funlightbids/core/components/funlightbids/ to store my php files and schema.
    Inside that folder, the build script failed at creating a /model/ directory. Why i am not really sure of. But the class files
    etc are in a folder thats names modelfunlightbids instead, cause that name could be created.

    Now, when i try to insert the data into the table i get : Fatal error: Call to a member function fromArray() on a non-object in C:\xampp\xampp\htdocs\funlightbids\core\components\funlightbids\snippet.ebbids.php on line 13

    This is a new setup i have made. I have tried to alter paths etc for 2 days. But it never matters, cause when it comes down to get the object it fails. I am getting tired and blind . Could someone see where i am going wrong?
    Tried to follow the doc as much as possible in this one to try to make it easier for you guys to comment. Really appreciate all the help i can get.

    The database is called funlightbids and inside that are all the modx tables including this eb_projects table.

    My schema:

    <?xml version="1.0" encoding="UTF-8"?>
    <model package="funlightbids" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" phpdoc-package="funlightbids" phpdoc-subpackage="model">
    
    	<object class="ebproject" table="eb_projects" extends="xPDOSimpleObject">
    		<field key="projectID" dbtype="int" precision="11" phptype="integer" null="false" default="" />
    		<field key="userID" dbtype="int" precision="11" phptype="integer" null="false" default="" />
    		<field key="zipCode" dbtype="int" precision="11" attributes="unsigned" phptype="integer" null="false" default="0" />
    		<field key="projectTitle" dbtype="varchar" precision="50" phptype="string" null="false" default="" />
    		<field key="projectDate" dbtype="date" precision="255" phptype="string" null="false" default="" />
    		<field key="projectDesc" dbtype="varchar" precision="1000" phptype="string" null="false" default="" />
    		<field key="projectBudget" dbtype="int" precision="10" phptype="integer" null="false" default="" />
    	</object> 
     	
    </model>  
    


    build.config.php
    <?php  
    define('MODX_BASE_PATH', dirname(dirname(dirname(dirname(dirname(dirname(__FILE__)))))) . '/funlightbids/');  
    define('MODX_CORE_PATH', MODX_BASE_PATH . 'core/');  
    define('MODX_MANAGER_PATH', MODX_BASE_PATH . 'manager/');  
    define('MODX_CONNECTORS_PATH', MODX_BASE_PATH . 'connectors/');  
    define('MODX_ASSETS_PATH', MODX_BASE_PATH . 'assets/'); 


    build.schema.php
    <?php
    /** 
     * Build Schema script 
     * 
     * @package storefinder 
     * @subpackage build 
     */  
    $mtime = microtime();  
    $mtime = explode(" ", $mtime);  
    $mtime = $mtime[1] + $mtime[0];  
    $tstart = $mtime;  
    set_time_limit(0);  
      $path = MODX_BASE_PATH;
     echo $path;
      require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/components/funlightbids/build.config.php';  
     echo 'included build.config file ';
    include_once MODX_CORE_PATH . 'model/modx/modx.class.php';  
    $modx= new modX();  
    $modx->initialize('mgr');  
    $modx->loadClass('transport.modPackageBuilder','',false, true);  
    $modx->setLogLevel(modX::LOG_LEVEL_INFO);  
    $modx->setLogTarget(XPDO_CLI_MODE ? 'ECHO' : 'HTML');  
      
      $root = dirname(dirname(dirname(dirname(dirname(__FILE__))))) .'/';  
    $sources = array(  
        'root' => $root,  
        'core' => $root.'core/components/funlightbids/',  
      'model' => $root.'core/components/funlightbids/model',  
        'assets' => $root.'assets/components/storefinder/',  
      'schema' => $root.'core/components/funlightbids/',  
    );  
    
    $manager= $modx->getManager();  
    $generator= $manager->getGenerator();  
    
    $generator->parseSchema($sources['schema'].'funlightbids.mysql.schema.xml', $sources['model']);  
      
    $mtime= microtime();  
    $mtime= explode(" ", $mtime);  
    $mtime= $mtime[1] + $mtime[0];  
    $tend= $mtime;  
    $totalTime= ($tend - $tstart);  
    $totalTime= sprintf("%2.4f s", $totalTime);  
      
    echo "\nExecution time: {$totalTime}\n";  
      
    exit ();​​ 

    snippet.ebbids.php
    <?php  
    <?php  
    /** 
     * @package storefinder 
     */  
    $base_path = !empty($base_path) ? $base_path : $modx->getOption('core_path').'components/funlightbids/';
    echo $base_path;
    $modx->addPackage('funlightbids',$base_path.'modelfunlightbids/');  
    
    $projects = $modx->getCollection('ebproject');  
    echo 'Total: '.count($projects);  
    
    $store = $modx->newObject('ebproject');  
    $store->fromArray(array(  
        'userID' => 1,  
        'projectTitle' => '12 Grimmauld Place',  
        'projectDesc' => 'London',  
          
    ));  
    $store->save();  
      
    $store = $modx->newObject('ebproject');  
    $store->fromArray(array(  
        'userID' => 2142,  
        'projectTitle' => '4 Privet Drive',  
        'projectDesc' => 'London',  
      
    ));  
    $store->save();   
      [url=http://www.williamastrom.se]Webdesign and CMS developer William
      • 3749
      • 24,544 Posts
      The only thing I can see is this:

      'model' => $root.'core/components/funlightbids/model',


      Should have a slash at the end:

      'model' => $root.'core/components/funlightbids/model/',


        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
        • 32360
        • 16 Posts
        I guess ill wait for a better documentation. Nothing seems to work, so ill go back and use regular php+mysql.
          [url=http://www.williamastrom.se]Webdesign and CMS developer William
          • 22303 MODX Staff
          • 10,725 Posts
          Just use the PDO functions that are available on xPDO. You do not have to have a custom xPDO model.

          But, here is your problem:
          $modx->addPackage('funlightbids',$base_path.'modelfunlightbids/');

          That should be:
          $modx->addPackage('funlightbids',$base_path . 'model/');

          funlightbids is the name of your package that will be added as a package search path starting at the root location of your model, not from the subfolder containing the actual model classes.