We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24629
    • 370 Posts
    Hi This must sound stupid, but since i can't find a descent class reference for modx i'm struggling with the simplest things like this one
    iwant to generate a submenu and need an aray of all siblings. i tried everything i could think of and nothing works
    $siblings = $modx->getCollection('modResource',array(
           'parent' => $modx->resource->get(parentid),     
           'published' => 1));
    


    how can i do this?
    tnx


      • 1778
      • 659 Posts
      Hello
      Not sure of what is exactly your goal, but why not use Wayfinder to generate your submenus ?
      Cheers
        • 3749
        • 24,544 Posts
         $parent = $modx->resource->getOne('Parent');
        $children = $parent->getMany('Children');


        BTW, your code would work if you changed parentid to parent.
          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
        • The MODX API reference is at http://api.modx.com, and some of the main classes are (partly) documented with more examples at rtfm.modx.com/display/revolution20/Class+Reference and rtfm.modx.com/display/xPDO20/
            Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

            Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
            • 24629
            • 370 Posts
            @ Bobray thx, can't wait for my book to arrive.

            @Mark . i know the API reference is there. But it is not as comprehensive and complete as i hoped.
            Maybe it is because i'm coming from an actionscript background and am used/spoiled to the as3 reference (http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/index.html?filter_flash=cs5&filter_flashplayer=10.2&filter_air=2.6). It has a clear inheritance structure, Syntax examples, all methods and properties(local and inherited)with each object etc.
            in the Modx api ref for instance the method getMany that Bob offered is not in there. and both references you offer seem to be different.

            The info is probably all in there but i cant make heads or tales from it. I realy hope Bobs book will have a slick API reference:)

            ralph
              • 24629
              • 370 Posts
              Hi,
              now i have the array of siblings and try to get the seperate pages out of there
              for($i=0; $i<count($siblings);$i++){ 
                    $res = $siblings[$i];
                    $output .= $res->get('id');
               }    


              Why does this not work??

              ralph
              • Would be good to see the entire script including how you get the siblings and return the values, to make sure there's no errors in there. What you posted looks fine.. though I would normally do it slightly different (but in essence the same):

                foreach ($siblings as $res) {
                   $output .= $res->get('id');
                }
                



                As for the API docs, that comes straight from the code's phpdoc comments so I suppose that's not entirely the right place for extensive examples.. that probably should get a place of its own though.

                If you're going into much development, it's probably best to keep the xPDO documentation nearby, this class reference can be of enormous help (and has quite some examples): http://rtfm.modx.com/display/xPDO20/Class+Reference

                The modX class is an extension to xPDO so it inherits all of its methods. All objects (users, resources, menus, etc) extend xPDOObject so they use all of those methods as well. [ed. note: markh last edited this post 12 years, 7 months ago.]
                  Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                  Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
                  • 3749
                  • 24,544 Posts
                  Mark meant to type this:

                  $output .= $res->get('id');


                  You did remember to do this, right?

                  return $output;


                  For diagnostic purposes, you might add this above the loop:

                  $output = 'Retrieved ' . count($siblings) . ' resources';
                    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
                  • Oops, thanks for that Bob. laugh
                      Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                      Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
                      • 24629
                      • 370 Posts
                      HI,

                      @ Mark i changed it to an foreach loop with an incremental because i needed to know the end of the loop.

                      @Bob i took your suggestion and changed to getMany and that worked.
                      the whole script is now

                      $output = '';
                      
                      $parent = $modx->resource->getOne('Parent');
                         if($parent){
                         $criteria = $modx->newQuery('modResource');
                         $criteria->where(array(
                                 'published' => 1,
                                 ));
                         $siblings  = $parent->getMany('Children',$criteria);
                      
                         if(count($siblings)>0){
                            $output .= "<div class='title'>". $parent->get('menutitle') ."</div>\n";
                            $output .= "<div id='navigation'>\n";
                            $output .= "<ul>\n";
                       
                             foreach ($siblings as $sibling) {
                                 $output .= "<li><a href='[[~".$sibling->get('id') ."]]'>".$sibling->get('pagetitle')."</a></li>";
                             }   
                          $output .= " </ul>\n</div>";
                         }
                      }
                      
                      return $output;

                      Still what is weird is that the returned array does let me retreive properties from the children when it is retreived with an foreach loop
                      foreach ($siblings as $res) {
                         $output .= $res->get('id');
                      }
                      works

                      and
                      for($i=0; $i<count($siblings);$i++){
                            $res = $siblings[$i];
                            $output .= $res->get('id');
                       }
                      does not work.

                      won't let me do $res->get('id');

                      why?? i have a similar problem in an another script now ( http://forums.modx.com/thread/70842/i-don-t---get-it#dis-post-396061). I'm sure there is something i'm not getting.

                      tnx
                      Ralph