We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    I’m not sure if the confusion is mine or MODx’s.

    I have a document (doc # 4) with the alias ’spfresponse’ which I’m trying to jump to in a snippet.

    If I use this code, the full url is produced correctly:

    $responseURL = $modx->makeUrl(4,'','','full');
    header("Location:".$responseURL);
    
    generates: http://mysite.com/home/spfresponse.html


    I need to use the alias, though, since the doc # will be different for different users.
    When I use this code, I get the wrong URL and the jump fails:

    $responseURL = $modx->makeUrl('','spfresponse','','full');
    header("Location:".$responseURL);
    generates: http://mysite.com/spfresponse.html



    It seems that using the alias should still produce the correct URL, no? Or am I just confused? Is there another way to generate a correct URL from a doc’s name or alias?

    A related problem is that I need to pass an argument to spfresponse. If FURLS are off, the argument will be appended to the argument to index.php and I think this will fail. Do I need to put the argument in a session variable to solve this?

    Bob


      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 second parameter does nothing. It forces the alias to what you provide (which is worthless), but still requires the id. It will be removed or re-appropriated for other uses in the near future.
        • 3749
        • 24,544 Posts
        Good to know. Thanks.

        It looks like getDocumentObject() will get the id from the alias which should solve the problem. It seems that a function for getting the document id from the title would be useful (perhaps as a method in getDocumentObject()).

        It might be worth thinking about extending getDocumnentIdentifier to get the id of documents other than the current one.

        Bob
          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
        • getDocumentObject is deprecated in favor of $modx->request->getResource() and this is not a public API method anyway, but rather a protected method used by the internal MODx engine. It should not be called directly in add-ons, but can be overridden by extensions (i.e. MyCMSClass extends modX).

          getDocumentIdentifier is also deprecated in favor of $modx->request->getResourceIdentifier(), and is also a protected method (not for direct use in add-ons).

          An alias is more than just a field on the resource; it is calculated now based on many factors, including content-type extensions, is it a container, and the parent aliases if alias paths are enabled.

          You can easily do custom searches for any kind of object using the new xPDO-powered public API’s:

          <?php
          $resource = $modx->getObject('modResource', array(
              'pagetitle' => $pagetitle,
              'deleted' => 0,
              'published' => 1,
          ));
          ?>


          Use $modx->sendRedirect() to redirect to another page, or sendForward() to get the response from another page without another request (i.e. url stays the same as original request).

          You can get an id from the full alias like so:
          <?php
          $docid = isset($modx->resourceMap['home/spfresponse.html'])
              ? $modx->resourceMap['home/spfresponse.html']
              : $modx->config['error_page'];
          ?>

          However, I do not understand how the same unique resource path would return different IDs since URL’s must be unique. huh
            • 3749
            • 24,544 Posts
            Also good to know.

            Is there any method I can use to calculate a full URL for a document that will work in both 0.9.6 and 0.9.7 9 (with or without FURLs on) when all I know for sure is the document’s title or alias (not the full alias, just the one filled in when creating the page)?

            Bob
              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
            • Quote from: BobRay at Dec 18, 2007, 05:09 PM

              Is there any method I can use to calculate a full URL for a document that will work in both 0.9.6 and 0.9.7 9 (with or without FURLs on) when all I know for sure is the document’s title or alias (not the full alias, just the one filled in when creating the page)?
              I don’t see how that would be possible, since multiple documents could have the same alias or pagetitle value. You need to find unique criteria to identify the id of the page you are searching for, or get a collection of them and evaluate additional criteria until you find the one you are looking for. Right?
                • 3749
                • 24,544 Posts
                Ouch. In theory, only one page will have the alias or pagetitle I’m looking for but I have no way of knowing ahead of time what its ID will be. It’s an unusual situation but inevitable for a snippet developer who puts code in separate pages and jumps between them (SPForm does this to increase spamproofness, though I’m beginning to wonder if it’s worth it).

                MODx’s assumption that all references to a page are by ID makes good sense from a design standpoint, but since the doc IDs for the pages containing the pieces of the snippet will be assigned when the user creates the pages, I can’t know ahead time what they will be. I can tell the user what alias and pagetitle to use, though, so I know those.

                It looks like I either use the DBAPI to find them, or have the user put the page IDs in the config file. I guess the second method would be both easier and more reliable.

                Thanks again for all your help. I know I’d never get this level of information from one of the principle coders at any other CMS. I love this forum... grin

                Bob
                  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