<?xml version="1.0" encoding="UTF-8"?> <model package="ecuadormycountryta" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" phpdoc-package="ecuadormycountryta" phpdoc-subpackage="model"> <object class="ecumctaSegment" table="tourismsegment" extends="xPDOSimpleObject"> <field key="segmentid" dbtype="integer" precision="20" phptype="integer" null="false" default="" index="index" /> <field key="segmentname" dbtype="varchar" precision="200" phptype="string" null="false" default="" index="" /> <composite class="ecumctaTa" key="tatype" local="tatype" foreign="segmentid" cardinality="many" /> </object> ---- other tables ----
include("xpdo.class.php");
$xpdo= new xPDO('mysql:host=localhost;dbname=ecuadortourism', '[user]', '[password]', '');
$segmentT = $xpdo->newObject('ecumctasegment',array(
'segmentname' => "Aventura"));
$segmentT->set('segmentname',"Ecoturismo");
$segmentT->save();<?php
include("xpdo.class.php");
$xpdo= new xPDO('mysql:host=localhost;dbname=ecuadortourism', 'root', 'exito2008','');
$xpdo->setDebug(true);
$xpdo->addPackage('ecuadormycountryta','/xpdo/_model/');
$xpdo->getObject('ecuadormycountryta.myObject');
$segmentT = $xpdo->newObject('ecumctaSegment',array(
'segmentname' => "Aventura"));
$segmentT->set('segmentname',"Ecoturismo");
$segmentT->save();
?>[2010-03-01 15:37:46] (ERROR @ /Pruebas/UseObjects.php) Path specified for package ecuadormycountryta is not a valid or accessible directory: /xpdo/_model/
So, I'm assuming you've built your model maps and classes, you'll just run this function:
Code:
$modx->addPackage('mypackagename','/path/to/my/model/');
// ie, for a package "test" in your "core/components/myapp/model/test/'
$modx->addPackage('test',$modx->getOption('core_path').'/components/myapp/model/');
This will add all the maps to the current xPDO instance so that it can grab the object definitions. You can then grab your classes (table objects) by doing:
Code:
$modx->getObject('test.myObject');
// or, alternatively, but a tiny bit slower, because it has to search for the package:
$modx->getObject('myObject');
<?php
$xpdo->addPackage('ecuadormycountryta', XPDO_CORE_PATH . '_model/');
?><?php
include("xpdo.class.php");
$xpdo= new xPDO('mysql:host=localhost;dbname=ecuadortourism', 'root', 'exito2008','');
$xpdo->setDebug(true);
$xpdo->addPackage('ecuadormycountryta', XPDO_CORE_PATH . '_model/');
$xpdo->getObject('ecumctaSegment');
$segmentT = $xpdo->newObject('ecumctaSegment',array(
'segmentname' => "Aventura"));
$segmentT->set('segmentname',"Ecoturismo");
$segmentT->save();
?>
$segmentT = $xpdo->newObject('ecumctaSegment',array(
'segmentname' => "Aventura"));$xpdo->getObject('ecumctaSegment');
<?php
include("xpdo.class.php");
$xpdo= new xPDO('mysql:host=localhost;dbname=ecuadortourism', 'root', 'exito2008','');
$xpdo->setDebug(true);
$xpdo->addPackage('ecuadormycountryta', XPDO_CORE_PATH . '_model/');
$xpdo->getObject('ecumctaSegment');
$segmentT = $xpdo->newObject('ecumctaSegment',array(
'segmentname' => "Aventura"));
$segmentT->set('segmentname',"Ecoturismo");
$segmentT->save();
?>
Everett,
So, I'm assuming you've built your model maps and classes, you'll just run this function:
Code:
$modx->addPackage('mypackagename','/path/to/my/model/');
// ie, for a package "test" in your "core/components/myapp/model/test/'
$modx->addPackage('test',$modx->getOption('core_path').'/components/myapp/model/');
This will add all the maps to the current xPDO instance so that it can grab the object definitions. You can then grab your classes (table objects) by doing:
Code:
$modx->getObject('test.myObject');$xpdo->addPackage('ecuadormycountryta', XPDO_CORE_PATH . '_model/'); $segmentT = $xpdo->newObject('ecumctaSegment',array(
'segmentname' => "Aventura"));<?php
include("xpdo.class.php");
$xpdo= new xPDO('mysql:host=localhost;dbname=ecuadortourism', 'root', 'exito2008');
$xpdo->setDebug(true);
/* set logging to output to console (in CLI mode) or browser */
$xpdo->setLogTarget(XPDO_CLI_MODE ? 'ECHO' : 'HTML');
/* use setPackage instead of addPackage so the package is at the top of the package search path */
$xpdo->setPackage('ecuadormycountryta', XPDO_CORE_PATH . '_model/');
/* here you create a new ecumctaSegment object instance with a segmentname of 'Aventura' */
$segmentT = $xpdo->newObject('ecumctaSegment',array(
'segmentname' => "Aventura"));
/* now you are changing the segmentname of this new object to Ecoturismo
(is this what you intended?) */
$segmentT->set('segmentname',"Ecoturismo");
/* now persist the new ecumctaSegment object to the database:
this should create a new row in the table with the segmentname Ecoturismo */
$segmentT->save();
?><?php
include("xpdo.class.php");
$xpdo= new xPDO('mysql:host=localhost;dbname=ecuadortourism', 'root', 'exito2008','');
$xpdo->setDebug(true);
$xpdo->setLogTarget(XPDO__MODE ? 'ECHO' : 'HTML');
$xpdo->setPackage('ecuadormycountryta', XPDO_CORE_PATH . '_model/');
$segmentT = $xpdo->newObject('ecumctaSegment',array(
'segmentname' => "Aventura"));
// $segmentT->set('segmentname',"Ecoturismo");
$segmentT->save();
?>$set= $this->addPackage($pkg, $path, $prefix);
$segmentT = $xpdo->newObject('ecumctaSegment',array(
'segmentname' => "Aventura"));foreach ($otherPkgs as $pkg => $pkgDef)
if ($class === false) {
$this->log(XPDO_LOG_LEVEL_ERROR, "Could not load class: {$classname} from {$fqn}.");
}$xpdo->setPackage('ecuadormycountryta', XPDO_CORE_PATH . '_model/');