We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22683
    • 41 Posts
    Hello, sorry if my English is not good. smiley

    I want to ask, can I get ID number from friendly URLs in modx?

    example :

    $modx->makeUrl(2) will result "/games" if I set Document’s alias in document number 2 become "games".

    How to get ID number from link "/games" ?



    regards

    pard1
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      That depends on what you are using this ID number for. If you want to find the Id of the page currently being processed (which will becomes the "games" page) then the MODx tag to get its ID would be [*id*]. If you’re using it in a snippet, you would use $modx->documentIdentifier.

      Some snippets, such as Ditto, that process many documents to make a list, use a placeholder [+id+] for the ID of the document they are processing at that point, while [*id*] would still indicate the main document where the snippet call is and where the list will be displayed.

        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 3749
        • 24,544 Posts
        If I’m understanding you, It sounds like you want your snippet to get the document ID of another document (not the current one) by using its alias. It can be done with a DB query, but it’s generally a bad practice (and very seldom necessary) because it may break if the alias changes. It’s also tricky (but can be done) if you want to process only published pages or pages the current user has access to.

        If you tell us why you want it and what you’re trying to do in more detail, maybe we can suggest another way to go about it.
          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
          • 22683
          • 41 Posts
          Thanks BobRay ,

          It can be done with a DB query, but it’s generally a bad practice (and very seldom necessary) because it may break if the alias changes.

          I agree, I want to know if there are other ways? if not I will use it grin

          If you tell us why you want it and what you’re trying to do in more detail, maybe we can suggest another way to go about it.

          Ok, I’m making snippet for show pages that many of visit.


          regards

          pard1
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            How are you keeping track of visits?
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 22683
              • 41 Posts
              How are you keeping track of visits?

              I use piwik for track of visits.. where piwik make tabel in my database and i can get link from there where pages much visited for my snippet.

              but i use friendly URLs.. and i want to change from friendly URLs link to number ID document..

              Can you help me?? grin



              Regards


              pard1
                • 4172
                • 5,888 Posts
                maybe thisone is helpful for you:
                http://www.partout.info/piwik_modx_en.html
                  -------------------------------

                  you can buy me a beer, if you like MIGX

                  http://webcmsolutions.de/migx.html

                  Thanks!
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  As long as you don’t have duplicate aliases it will be a simple query to the database. If you have alias paths and duplicate aliases, it gets more complicated.

                  You have the alias you want to look up, so query like this:
                  $result = $modx->db->select("id", $modx->getFullTableName("site_content"), "alias ='" . $alias . "'");
                  if($modx->db->getRecordCount($result) == 1) {
                      $docId = $modx->db->getValue($result);
                  }
                  


                  (sorry about that, had to run an errand before I could test it; this one works)
                    Studying MODX in the desert - http://sottwell.com
                    Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                    Join the Slack Community - http://modx.org
                    • 22683
                    • 41 Posts
                    Thanks.. for help.. Bruno17 and Sottwell, really help me laugh

                    Hello Bruno17, I try plugin piwik from link that you show.. but i have problem.. do you know why "Action getLastVisitsGraph not found in the controller Piwik_VisitsSummary_Controller" not show..?? huh



                    Regards

                    pard1
                      • 1343 ☆ A M B ☆
                      • 2,213 Posts
                      Quote from: Bruno17 at Jun 08, 2009, 03:44 AM

                      maybe thisone is helpful for you: *LINK REMOVED*

                      Chrome is flagging that site as having malicious content... I’m guessing it’s over protective?
                        Patrick | Server Wrangler
                        About Me: Website | Tweets |  MODX Hosting