We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 11365
    • 39 Posts
    Hi
    Sorry for my bad english)))

    I have created custom manager pagesuch as here http://rtfm.modx.com/display/revolution20/Custom+Manager+Pages+Tutorial
    and now I want to use database, but when run code
    $query = $modx->newQuery('modTemplateVarResource');
    $query->innerJoin('modResource','Resource');
    $query->where(array(
        'value' => $val
    ));
    $parent = $modx->getObject('modTemplateVarResource',$query);
    

    where $val is value from prev. code
    but I see message "Error!"

    how can I use db here?
      • 3749
      • 24,544 Posts
      Is resource your own custom DB table? If so, you need to create or generate a schema for it and create class and map files so that xPDO can use your table.

      See the tutorial here: http://bobsguides.com/custom-db-tables.html
        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
        • 11365
        • 39 Posts
        No. I use standart modx tables.
        I want to get row from `modx_site_tmplvar_contentvalues`
          • 3749
          • 24,544 Posts
          OK. What information, exactly, are you trying to get? There may be an easier way.
            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
            • 11365
            • 39 Posts
            All right.

            I want to import data from CSV to database.
            I have car models: x-trail, nararro, ...
            and I have complectations:
            for x-trail: asdd, fdg656, dfg6-fdg, ...
            in each complectation I have describings of engine, count of doors, transmission and etc...

            Structure of site must be:
            model:
            compl1
            compl2
            ...
            That’s why engine, count of doors, transmission, I think, must be TV’s in compl1, compl2,...

            First of all I read CSV
            then create document
            then fill TV’s for this document

            but I can’t use xPDO in custom manager page... Is it normal or, may be, I should reinstall MODx?
              • 3749
              • 24,544 Posts
              That can definitely be done, but it’s fairly wasteful to use a whole resource and a bunch of TVs for every car and searches would be very complicated and very slow. Both resources and TVs carry a lot of overhead that you don’t need at all and the TVs would require a complex search strategy. The code to add a new car would also be a pain to implement and all the code would be hard to maintain because you’d have no separation between the model and the view.

              I’d suggest importing the CSV file (or the original table) into the MODx DB, but with your own table prefix in the table name (call the table something like ’griz_cars’). Add any indexes you want for the table. Then use a procedure like the one described here: http://bobsguides.com/custom-db-tables.html to create the schema, class, and map files for the table.

              That will make the table xPDO-friendly. Once you’ve done that, adding cars, displaying them, and searching for subsets of them will be infinitely easier and faster. Here are a couple of examples:

              <?php
              /* add new car */
              $feilds = array(
                  'make'=>'ford',
                  'model'=>'mustang',
                  'doors'=>'4',
                  'miles'=>'23,231',
                 'engine_type'='diesel'
              );
              
              $car = $modx->newObject('car',$fields);
              $car->save();
              
              /* Find all fords */
              
              $cars = $modx->getCollection('cars',array('make'=>'ford'));
              foreach($cars as $car) {
                 $output .= '<br />MAKE: ' . $car->get('make');
                 $output .= '<br />MODEL: ' . $car->get('mode';);
                 // etc.
              }
              return $output;
                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
                • 11365
                • 39 Posts
                Thank you, Bob.
                You really helped me! smiley

                I had the same idea but went a wrong way.

                PS "Учиться, учиться и еще раз учиться"
                ("Education, education and education...")
                  • 3749
                  • 24,544 Posts
                  You’re welcome. smiley
                    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