We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 41127
    • 23 Posts
    I'm new with modx and have worked most with drupal. My new employer works with modx and now im starting to explore and discover modx and i must say that it's pretty good and makes development fast.

    Here's what i cant figure out. I want to simulate the $q. I have a plugin that runs on a request (babel multilingual) and now i am tuning that plugin to fit more of oure needs. So now i do not want to return a $q trough htaccess because that gives not te desired result since i have to do some more checks.

    So the question now is how do i tell modx within a plugin that runs on a request that i want to get a document and return / show it. Because at this moment it just prints the home document since i have not told modx what document to return.

    Here's the snippet:
    if($modx->context->get('key') != "mgr"){
        switch ($_REQUEST['cultureKey']) {
            case 'de':
                /* switch the context */
                $modx->switchContext('de');
                if(isset($_REQUEST['langProduct']) && $_REQUEST['langProduct'] != 'booten'){
                  $modx->sendErrorPage();
                } else {
                  $getJacht = $_REQUEST['langProduct'];
    
                  We got a result and now we need to tell modx that we want to display a specific document by passing an document id and returning that...
    
                }
                break;
            case 'en':
                /* switch the context */
                $modx->switchContext('en');
                if(isset($_REQUEST['langProduct']) && $_REQUEST['langProduct'] != 'yachts'){
                  $modx->sendErrorPage();
                }
                break;
            default:
                /* Set the default context here */
                $modx->switchContext('web');
                if(isset($_REQUEST['langProduct']) && $_REQUEST['langProduct'] != 'jachten'){
                  $modx->sendErrorPage();
                }
                break;
        }
    
        unset($_GET['cultureKey']);
        unset($_GET['langProduct']);    
    }
    


    Here's the htaccess
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(nl|en|de)/(jachten|yachts|booten)/details/(.*)/(.*).html$ index.php?langProduct=$2&cultureKey=$1&lang=$1&getJacht=$3 [L,QSA]
    


    Now why i want to return a document is because in that document i am calling a snippet which includes another script which we use that prints values trough a SOAP call so i don't have the values in the modx database and i can not return modx documents physically and that is why i am using this construction.

    Of course if there's a better option or suggestion i am open to hear it since i'm starting with modx. [ed. note: michalski last edited this post 14 years, 1 month ago.]
      • 41127
      • 23 Posts
      After reading my post i think what i actually want is a call like
      $modx->switchContext
      that does something like switchDocument.
        • 39932
        • 483 Posts
        You have many options for this. If you simply want to not change the URL but show a different document:

            $id = The Resource ID you wish to show.
            $modx->sendForward($id);
        


        Other solutions may be more complex depending upon need.

        Note: This does not switch contexts. This simply shows a different document. Context Switching is an entirely different process with its own considerations.
          Website: Extended Dialog Development Blog: on Extended Dialog
          Add-ons: AJAX Revolution, RO.IDEs Editor & Framework (in works) Utilities: Plugin Compatibility List
          Tutorials: Create Cross-Context Resources, Cross-Context AJAX Login, Template-Based Actions, Remove Extensions from URLs

          Failure is just another word for saying you didn't want to try. "It can't be done" means "I don't know how".
          • 41127
          • 23 Posts
          thnx
            • 3749
            • 24,544 Posts
            sendForward is a good option, if you want to use the template of the page with the sendForward() snippet on it and not change the URL. If you want to actually forward the user to that page (and use its Template and URL), you can use $modx->sendRedirect($url).

            If you just want to display some of the resource's fields, you can also get the resource and pull them:


            $resource = $modx->getObject('modResource', array('pagetitle' => $_REQUEST['langProduct']));
            
            $output = '<p>Title: ' . $resource->get('longtitle') . '</p>';
            $output .= '<p>Content: ' . $resource->getContent() . '</p>';


            Note that the content field is retrieved with $resource->getContent(). All other fields with $resource->get('fieldname');


            ------------------------------------------------------------------------------------------
            PLEASE, PLEASE specify the version of MODX you are using.
            MODX info for everyone: http://bobsguides.com/modx.html [ed. note: BobRay last edited this post 14 years, 1 month ago.]
              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
              • 39932
              • 483 Posts
              Some Additional Details on $modx->sendForward()

              sendForward() allows you to send the user to a Resource in MODx without changing the URL. This means that it keeps the $_REQUEST, $_GET and $_POST of the original request. Within MODx, directly, sendForward is treated as if it were a new page load. This means that it fires OnLoadWebDocument and OnLoadWebCached. When the document loads, it is loaded with all of the attributes of the saved resource, with the exception of the URL. This means if the document is cached, it will retrieve from the cache first.

              sendForward() may also be chained, even into a sendRedirect(). Each time the forward is made, the new document will be reloaded completely (so far, up to 3). [ed. note: fuzzicallogic last edited this post 14 years, 1 month ago.]
                Website: Extended Dialog Development Blog: on Extended Dialog
                Add-ons: AJAX Revolution, RO.IDEs Editor & Framework (in works) Utilities: Plugin Compatibility List
                Tutorials: Create Cross-Context Resources, Cross-Context AJAX Login, Template-Based Actions, Remove Extensions from URLs

                Failure is just another word for saying you didn't want to try. "It can't be done" means "I don't know how".
                • 3749
                • 24,544 Posts
                Yes, that's what I meant to say. I changed the wording of my post and forgot to take out the word 'don't'. Fixed above.


                ------------------------------------------------------------------------------------------
                PLEASE, PLEASE specify the version of MODX you are using.
                MODX info for everyone: http://bobsguides.com/modx.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