We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40092
    • 265 Posts
    Well, this XPDO thing rocks.

    I have now gotten it down to this:

    $items = $modx->getCollection('Table', array('actief' => 1, 'frontpage' => 1));


    Wich is exactly what i want it to do, except limit it to 3.
    I thought, well, that's just an extra parameter, so let's add limit('0', '3') behind the array.
    That ship didn't sail, neither does $items->limit('0', '3')

    What am i missing?
      • 42049 ☆ A M B ☆
      • 250 Posts
      If you refer to me previous example, construct the query, pass in your parameters, then pass into your call.
      Notice the two calls to Table...

      //Query the table
      $query = $modx->newQuery('Table');
      $query->where(array(
          'actief' => 1,
          'setfrontpage' => 1,
      ));
      
      //Limit the results AFTER your initial where's (offset start, number to return)
      $query->limit('0', '3');
       
      //Fetch the results as a collection of objects with our custom query attached
      $items = $modx->getCollection('Table', $query);

        GEL STUDIOS
        MODX Professional | MODX Ambassador

        Website | Email | Twitter | Facebook
        • 40092
        • 265 Posts
        So i have to construct a query.

        I just thought that i could shorten the code to what i've done above. But that's a no go, i presume?
          • 42049 ☆ A M B ☆
          • 250 Posts
          If you do it that way, its enhances readability also, I think with a limiting factor such that you have to construct it in that way. (Could be wrong)

          I've never short handed queries like that, nothing worse than jumping back in a few weeks later and wasting time trying to decode what you did tongue
            GEL STUDIOS
            MODX Professional | MODX Ambassador

            Website | Email | Twitter | Facebook
            • 8386 ☆ A M B ☆
            • 160 Posts
            If you want it shorter then write.

            //Query the table
            $query = $modx->newQuery('Table')->where(array('actief' => 1, 'setfrontpage' => 1))->limit('0', '3');
            
            //Fetch the results as a collection of objects with our custom query attached
            $items = $modx->getCollection('Table', $query);
            


            Now it only 2 lines, but you decrease readability. I would say stick to the format that Gel Studios provided as this is what is being used in most extras and modx core itself.
              • 40092
              • 265 Posts
              This makes sense, again smiley. But, you two are right, for readability this is not the best option. I will use the full and readable code instead.

              Thanks guys, this really helped me understand the way it works, in basics offcourse.
              Now i'll go wrestle myself through the rest of the XPDO docs.
                • 42049 ☆ A M B ☆
                • 250 Posts
                We all started from the exact same place mate! Understanding the core of it makes understanding the rest of the docs so much easier!

                Enjoy XPDO!
                  GEL STUDIOS
                  MODX Professional | MODX Ambassador

                  Website | Email | Twitter | Facebook