We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36565
    • 73 Posts
    Hi everybody,

    thanks for taking a look! On to the meat:

    I have run the reverse-engineering script on my database and added some aggregate relationships - so this *should* be fine. I have attached my up-to-date XML Schema.

    In a snippet, I want to output a property of an object that I know is in a table called "CDs" and has a primary key value of 2, for example.

    First, I have some xPDO code that gets me connected to the DB - correctly, as I assume from the 'Connected' output. Then I add the "package". I assume this works as well, because if I change the package path to something else, I get errors, while with this actual path I get none, and it is where the package resides.

    $host = 'localhost';                                     
    $port = 3306;                                                       
    $database = 'mydatabasename';
    $username = 'myusername';
    $password = 'mypassword';
    
    $dsn = "mysql:host=$host;port=$port;dbname=$database";
    $db = new xPDO($dsn, $username, $password);
    echo $o=($db->connect()) ? 'Connected' : 'Not Connected';
    $db->addPackage('Inventardatenbank','/core/components/Inventardatenbank/model/','');
    
    $cd = $db->getObject('CDs', 2);
    print('Testausgabe' . $cd);                    //This prints "ConnectedTestausgabe" plus nothing plus "Test"
    print('Testausgabe' . $cd->get('Besitzer'));    //This should print "Testausgabe" plus a value, but output stops after 'Connected'
    print('Test');


    When I try to load the 'Besitzer' value with $cd->get('Besitzer'); something goes wrong. My guess is that the getObject call returns null. But why?

    This question has been answered by opengeek. See the first response.

    [ed. note: neo2.0 last edited this post 14 years, 3 months ago.]
      PHP illiterate MODx enthusiast
      • 22303 MODX Staff
      • 10,725 Posts
      Don't try to echo or print the whole $cd object. Use $cd->toArray() to see the fields and their values.
        • 36565
        • 73 Posts
        OK, thanks!

        I substituted both lines with the following one:
        print('Testausgabe' . $cd->toArray());

        The result is that output stops after 'Connected', indicating some error.
        I will appreciate hints on how to understand or debug the situation.
          PHP illiterate MODx enthusiast
          • 36565
          • 73 Posts
          Hey guys,

          I need your help here - any ideas how you would get more info about what goes wrong?
          Maybe there are some useful xPDO error messages waiting to be caught?
          How can I access them?

          Thanks!
            PHP illiterate MODx enthusiast
          • discuss.answer
            • 22303 MODX Staff
            • 10,725 Posts
            Is your package really located in a root directory of your machine called /core/ ? The model path for addPackage() should be an absolute path.
              • 36565
              • 73 Posts
              Thanks opengeek, you are great!
              Fun with MODx development just came back to me smiley

              I *had* read that somewhere and tried that out, I'm sure. Don't know why it escaped me.
                PHP illiterate MODx enthusiast