We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40359
    • 25 Posts
    I created new rows in table modx_site_content, city and image...
    I don't need to display them when editing resource, because I'm only going to resave tv value in it, because I have a lot of resources, and getResources is very slow, so I'm getting values directly from modx_site_content database. This is working function:

    $resource =& $scriptProperties['resource'];
    $city = $resource->getTVValue('city');
    $resource->set('longtitle',$city);
    $resource->save();
    


    But when i add:

    $resource->set('city',$city);
    


    It doesn't save value to database...
    Can anyone help me with this please?
      • 40045
      • 534 Posts
      I'm not an xpdo expert (far away from that actually =D) but I would say that cannot work because you probably didn't add these fields to the xml schema file right? (as far as I understand, you went into phpmyadmin and added the new rows??)

      have a look at core/model/schema/modx.mysql.schema.xml beginning at line 789, that's were the fields are saved and I think as long as it's not in there it's not in the xpdo object and thus not accessible with xpod methods like ->set() or whatever =). And the working code you posted doesn't make use of your newly created fields right, it just sets the longtitle of the resource to the $city variable. The not working code tries to access the new field but that isn't existing for xpdo...

      hope I'm not telling you complete bulls***^^

      Ah, and you definitely shouldn't do stuff like that =), don't know if all of this will be gone after the next modx update you install...so you should really use a normal TV and then maybe get that TV value "normally" (if you really don't like to use getResources > have a look at includeTVList, maybe set processTVs to 0 and so on...there is a lot of optimization potential within getResources) with a custom snippet using barebones xpdo like

      $page = $modx->getObject('modResource', 123);
      return $page->getTVValue('city');
      


      more info here: http://rtfm.modx.com/display/revolution20/Accessing+Template+Variable+Values+via+the+API [ed. note: exside last edited this post 13 years, 10 months ago.]
        • 3749
        • 24,544 Posts
        As exside says, modifying core DB tables is definitely not recommended. You should consider one of the following:

        1. co-opting unused Resource fields for your data (this is the fastest)

        2. Using Template Variables

        3. Custom Resource Classes: http://rtfm.modx.com/display/revolution20/Custom+Resource+Classes

        4. A custom DB table and custom xPDO object to use instead of the Resource object
          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
          • 40359
          • 25 Posts
          Thank you for help, I used introtext to save several TVs inside, with delimiter, so I can split them in my snippet...

          I'm using this code for getting data from database:

          $resource = $modx->query("SELECT * FROM modx_site_content WHERE template = 7 AND published = 1 ORDER BY menuindex ASC");
          $types = $resource ->fetchAll(PDO::FETCH_ASSOC);
          


          getResources is impossible slow, it takes about 25 seconds to get 200 resources with TVs, but getting them directly from database, job is finished in 200 milliseconds... :/

          Little more help. smiley
          Because I already have 200 resources, is there some way for resaving all resources automatically, to store TVs inside introtext?
          And I have a large image for every resource, in TV, image path is also saved in introtext, but, is there a way to make small thumbnail, store it in some folder (thumbnails), and save that thumbnail path? [ed. note: bsehovac last edited this post 13 years, 10 months ago.]
            • 40045
            • 534 Posts
            =)), mate, you're making your life sooo difficult^^...I'm sure "putting all TV data into one resource field" wasn't what bob meant with "co-opting unused resource fields" =D

            I would suggest you have a look at the MIGX extra (which does saving multiple TVs in one, as JSON) and getImageList to output the whole stuff.

            For your "already have 200 resources" problem I actually don't have a ready solution, but maybe try the extra Batcher, but I'm not sure if this is able to do what you want.

            For the thumbnail stuff: If you have your imagepath in a separate field that should not be a big thing, just have a look at the phpthumbof extra =)...actually with MODx you don't have to reinvent the wheel or just start the "conversation" with a tank (eg. hacking the core), this is not wordpress =) (sorry @ all the wordpress lovers out there). [ed. note: exside last edited this post 13 years, 10 months ago.]
              • 40359
              • 25 Posts
              I'm not very good with xPDO and customizing resource fields, so this is the easiest solution for me...:)

              Main problem is speed of getting resources data, i have them 200 now, and it is going to be more then 1000. It is tourism site with list of all hotels, motels, restaurants, bars and a lot more, in my country. Every content is put into category, but also, every one of them need to be filtered by city, what I accomplished by putting it in city TV.

              So there is search engine, which filter them by category and city, caching is impossible, and getResources is unthinkable slow...

              I think this is the best and the fastest option...