We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10031
    • 69 Posts
    Now, I want to add data inside one table defined in the following schema:
    <?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 ----


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


    but appear the following errors,
    2010-02-26 18:37:28] (ERROR @ /Pruebas/UseObjects.php) Could not load class: ecumctasegment from mysql.ecumctasegment.
    and,
    Fatal error: Call to a member function set() on a non-object in E:\Program Files\xampp\htdocs\Pruebas\UseObjects.php on line 8

    then I am not obtaining instantiating of xpdo.

    Would you please help me with your important recommendations?
      • 28215
      • 4,149 Posts
        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
        • 10031
        • 69 Posts
        splittingred,
        thank for your reply,

        I had added the code to add package:

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

        but,
        the error is the following:
        [2010-03-01 15:37:46] (ERROR @ /Pruebas/UseObjects.php) Path specified for package ecuadormycountryta is not a valid or accessible directory: /xpdo/_model/


        I have used the path: /xpdo/_model or only /_model, that is the folder where appear the information of the model(attached jpg file)

        As well, I have verified:
        http://modxcms.com/forums/index.php/topic,41690.0.html
        and, from one part appear your reply:
        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');
        


        Then, I conclude that in my path /_model, lack something,

        Would you please help me inform why addpackage is not working now?
        Also, I think that is very important complete the documentation from:
        http://svn.modxcms.com/docs/display/xPDO20/Loading+Packages
        because from here does not appear complete information about path and GETOBJET to grab the object definitions.
          • 10031
          • 69 Posts
          I forgot send the jpg file where appear the folders of my model

            • 22303 MODX Staff
            • 10,725 Posts
            Your model path from the image appears to be /xampp/htdocs/xpdo/_model/ (if this is windows, probably c:/xampp/htdocs/xpdo/_model/, which would be easily obtained in your case by using XPDO_CORE_PATH . ’model/’ instead, so:
            <?php
            $xpdo->addPackage('ecuadormycountryta', XPDO_CORE_PATH . '_model/');
            ?>

            The path should be an absolute file system path to the location of your model on the hard drive.
              • 10031
              • 69 Posts
              Thanks,
              OpenGeek

              The paht is complete.

              Now, I keep on with the debug of the code:
              <?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();
              ?>
              

              but
              with the code line:
              $segmentT = $xpdo->newObject('ecumctaSegment',array(
                    'segmentname' => "Aventura"));

              is not created the object.

              Then the code line:
              $xpdo->getObject('ecumctaSegment');
              

              is not working.

              When I see from the window debug (attached jpg file), the function getObject does not charge by default, the className. Consequently, finishing the debug appear the error message (also attached file)

              Would you please help me for that the save in the database is okay?
                • 28215
                • 4,149 Posts
                Fran, you need to read the xPDO docs thoroughly - newObject does not save the object. You’ll need to do that first.

                http://svn.modxcms.com/docs/display/xPDO20/Setting+Object+Fields

                Also, getObject requires a 2nd parameter:

                http://svn.modxcms.com/docs/display/xPDO20/Retrieving+Objects

                Please read the manual before proceeding from here.
                  shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
                  • 10031
                  • 69 Posts
                  I understand what happened

                  The English is not my native language, and I believe that I could not explain very well the situation.

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


                  I used getObject in the code:
                  $xpdo->getObject(’ecumctaSegment’);
                  after I reviewed:
                  http://svn.modxcms.com/docs/display/xPDO20/Creating+Objects
                  and:
                  http://svn.modxcms.com/docs/display/xPDO20/Loading+Packages

                  but, I did not get the following code create the objet:
                  $segmentT = $xpdo->newObject(’ecumctaSegment’,array(
                  ’segmentname’ => "Aventura"));

                  Then I reviewed additional information about Loading packages:
                  http://modxcms.com/forums/index.php/topic,41690.0.html

                  and appear the following recommendations:

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


                  Therefore, the problem here is that I have not gotten to grab classes (table objets) by doing:
                  $modx->getObject(’test.myObject’)
                  as is suggested from:
                  http://modxcms.com/forums/index.php/topic,41690.0.html

                  Would you please inform me why is the reason for that only with:
                  $xpdo->addPackage('ecuadormycountryta', XPDO_CORE_PATH . '_model/');  

                  as appear in the documentation from:
                  http://svn.modxcms.com/docs/display/xPDO20/Loading+Packages
                  I can not obtain a new object as appear in the documentation:
                  http://svn.modxcms.com/docs/display/xPDO20/Creating+Objects
                  with my instruction:
                  $segmentT = $xpdo->newObject('ecumctaSegment',array(
                        'segmentname' => "Aventura"));


                  I appreciate your understanding if my writing in English is not so good.
                    • 22303 MODX Staff
                    • 10,725 Posts
                    Let me explain in code comments what you are doing here while also suggesting a how you should do it...
                    <?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();
                    ?>
                      • 10031
                      • 69 Posts
                      OpenGeek,

                      Now, I have updated the code with your recommendations:
                      <?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();
                      ?>


                      and, I am using the debug tool of eclipse and I can observe that the pkg variable keep the status <Unintialized> after to excecute the instruction:

                      $set= $this->addPackage($pkg, $path, $prefix);

                      inside the function setpackage,

                      (please see the jpg file attached:debug1.jpg)

                      After from
                      $segmentT = $xpdo->newObject('ecumctaSegment',array(
                            'segmentname' => "Aventura"));


                      in the function _LoadClass

                      executing the instruction:
                      foreach ($otherPkgs as $pkg => $pkgDef)

                      after to execute two breaks, the conditional instruction is activated:
                      if ($class === false) {
                                  $this->log(XPDO_LOG_LEVEL_ERROR, "Could not load class: {$classname} from {$fqn}.");
                              }

                      and the debug is interrupted with the message that the "apache http server is stopped workting"
                      (please see the jpg file attached:debug2.jpg)

                      Would you please inform me if this confirm that the class is not instanced and the instruction:
                      $xpdo->setPackage('ecuadormycountryta', XPDO_CORE_PATH . '_model/');

                      is not working correctly?