We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 50497
    • 30 Posts
    I have multiple custom database table and I have formit2db working or seemingly working. I'm not completely proficient with xPDO or PHP, but I'm kind of feeling my way through it based on the various tutorials and posts to this board.

    I have created 2 snippets for gathering id's from various tables.

    The first one is pulling the user id of the current logged in user:

    $UserID = $modx->user->get('id');
    return $UserID;


    Pretty straight forward and seems to be working. My second snippet is what's causing me issues.

    $UserID = $modx->user->get('id');
    $path = MODX_CORE_PATH . 'components/companyProfiles/';
    $result = $modx->addPackage('companyProfiles',$path .
        'model/');
     
    /*if (! $result) {
        return 'failed to add package';
    } else {
        $output = '<p>added Package</p>';
    }*/
    $companies = $modx->getObject('companyProfile',array('FK_UserId'=>$UserID)); 
    $output = $companies->get('id');
    
    
    return $output;


    Basically, I want to output the ID of the companyProfile table where the FK_UserId fields equals the current User ID. It's outputting an ID, but there may be a better and more efficient way of doing this. My problem is when I try to insert it into the database with formit2db. All fields are inserting correctly except for the companyID. I have the field value="[[!getCompanyID]]" and it shows the value it should in the field, but it's not inserting into the table. The value for [[!getUserID]] is working fine, so maybe there's something wrong with the snippet?
      • 4172
      • 5,888 Posts
      Are you trying to force an autoincrementing field (id) to another value, when saving the object?
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 50497
        • 30 Posts
        No, it's not auto incrementing.

        I recreated my table and package and it seems to be working now.

        I never really figured out why it wouldn't insert. I removed the snippet as the value and entered it manually and it still wouldn't hold a value. That's when I realized it's definitely broken further down the line.
          • 3749
          • 24,544 Posts
          Since you're connecting company profiles to MODX users, you might look at ClassExtender. It will extend modUser and create the company profile table (the userData object) for you once you tell it the fields you want.




            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting