We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1453
    • 17 Posts
    I am new to xPDO. I have successfully revers-engineered my database tables into xPDO schema file. Then, I generated model objects using xPDO generator.

    However, I get an empty object back when I try to retrieve my object from the database using xPDO. Even when I try to get a collection, I get an empty array.


    require("xpdo/xpdo.class.php");
    $xpdo= new xPDO(’mysql:host=localhost;dbname=spinculture’,’root’,’12345678’,’’);
    $xpdo->addPackage( ’spinpackage’, ’C:/spinculture/workspace/UpcomingImport/model’, ’’);

    $event = $xpdo->getObject( ’EpMemberevents’, array( "memberEventId" => 17 ) );
    echo "Event: " . get_class($event) . "\n"; // RETURNS an empty object

    $eventList = $xpdo->getCollection( ’EpMemberevents’);
    print_r( $eventList ); // RETURNS an empty array



    Here is the schema definition for the map:

    <object class="EpMemberevents" table="ep_memberevents" extends="xPDOObject">

    <field key="memberEventId" dbtype="int" precision="11" attributes="unsigned" phptype="integer" null="false" index="pk" generated="native" />

    <field key="memberId" dbtype="int" precision="11" attributes="unsigned" phptype="integer" null="false" />

    </object>


    I am quite sure of the database connectivity credentials and package path because I used the same when I reverse-engineered the database.

    Any help would be greatly appreciated.
      • 14784
      • 16 Posts
      I’m not certain, but you may need to add a ’/’ after model when you call addPackage. It should need the full path including that trailing slash.

      Also, if you are going to be calling several classes from that same model you may want to use setPackage instead of addPackage, so it will keep that package at the top of the search path when calling other objects.

      Hope that helps. If not, you may want to throw:
      $xpdo->setLogTarget('HTML');
      $xpdo->setDebug();
      

      after you include xPDO. May overload you a bit on the info, but certain helps when it seems like everything should be working and just isn’t.

      Oh, and http://modxcms.com/forums/index.php?topic=46318.0 had a pretty good discussion about all of this as well.
        • 1453
        • 17 Posts
        Wonderful... That was very helpful.
        Thanks!