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();