We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 11650
    • 15 Posts
    Ok so long story short, I have a buddy that made a couple of add-ons for ModX to allow for him to create a business listing page for his website since it’s a community portal. However, he want’s his business links, the links that take you to that specific business’ details page, to be friendly urls. Here is an example:

    Before

    http://domain.com/businesses.php?businessid=12345

    After

    http://domain.com/businesses/business-name-here.php

    Now what I’m curious about is what do I need to incorporate into his add-ons for it to utilize the SEO functions of the CMS and create the urls in that format. He asked me because I’m somewhat experienced in PHP but unfortunately I’ve never worked with modx before. What I have done so far is created a column for the businesses table in the DB called "friendly_name" and populated all the rows with their respective data in that field. I just need to know what I need to implement into the add-on so it will associate the friendly name with the id and how to result in displaying the page’s content within the design, so it doesn’t just bring up a white page with the result.

    Any help is greatly appreciated.
      • 18373 ☆ A M B ☆
      • 3,141 Posts
      MODx makes friendly urls for the resources - the pages.


      So you’ll want the addon he’s made to be called on a resource (named Businesses with businesses as alias). That page will most likely contain a snippet call that either gets the information of the business, specified by the businessid GET paramater, or show an overview of some sorts.


      Now, you’ll need some rewriting to achieve your friendly urls with the business title in the link... that’s something I’m not sure about how to achieve. I do know that you can have an url rewrite that simply fetches an ID out of your url and use that, while ignoring the rest.

      So you could do /businesses/12345/some-name-here.html, which modRewrite parses to become /businesses.{friendlyurlssuffix}?businessid=12345. It simply ignores the some-name-here.



      As a side note: you could’ve simply added all business listing as a resource within MODx and use something like Ditto or getResources for Revo to list them, while using a template to display the details, to keep everything in MODx and make use of the native Friendly URLs system.
        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.
        • 11650
        • 15 Posts
        Thanks for the advice. That sounds like an idea. I did find this post though regarding trying to access a page that is controlled by an addon and using SendForward() to display the resource’s specific page.

        Quote from: OpenGeek at Oct 27, 2009, 10:19 PM

        You can author a plugin that uses $modx->sendForward() and is registered to the OnPageNotFound event that does whatever you want. Here is an example:
        <?php
        /*
        this should be the Resource id of the page containing your view Snippet
        */
        $productResourceId = 21;
        
        $requestURI = trim($_SERVER['REQUEST_URI'], '/');
        $requestParts = explode('/', $requestURI, 2);
        if (count($requestParts) == 2) {
            if ($requestParts[0] === 'store') {
                /* 
                this assumes you have a product table with an alias field for specifying the relative product URL as t-shirts/v-neck.html
                */
                $productId = $modx->db->getValue("SELECT `product_id` FROM `product` WHERE `alias` = '{$requestParts[1]}'");
                if (intval($productId)) {
                    /*
                    set the productId into the $_GET variable for your product view Snippet to use
                    */
                    $_GET['productId'] = $productId;
                    /*
                    now forward the request to your Resource containing the product view Snippet
                    (forwarding does not change the requested URL like a redirect)
                    */
                    $modx->sendForward($productResourceId);
                }
            }
        }
        
        ?>


        But when he says I can author a plugin to do it, how do I do that?
          • 18373 ☆ A M B ☆
          • 3,141 Posts
          I think with authoring a plugin he means writing it.

          The code he posted should go into a new plugin, which fires on the "onPageNotFound" event.

          You’d have to make the links manually and modify the plugin code you quoted to look for a business instead of a tshirt, but then you’ll be good to go?
            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.
            • 11650
            • 15 Posts
            Quote from: Mark at Jun 28, 2010, 06:49 AM

            I think with authoring a plugin he means writing it.

            The code he posted should go into a new plugin, which fires on the "onPageNotFound" event.

            You’d have to make the links manually and modify the plugin code you quoted to look for a business instead of a tshirt, but then you’ll be good to go?

            Right...but where do I make a plugin. It it done through the admin panel. Or is it done by making a single php file? Any info on how I can do that would be appreciated.
              • 28042 ☆ A M B ☆
              • 24,524 Posts
                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
                • 11650
                • 15 Posts
                Quote from: sottwell at Jun 28, 2010, 10:52 AM

                http://www.sottwell.com/how-plugins-work.html

                I found that article on google yesterday, but the admin panel looks nothing like that.

                How would I get to in from here?

                  • 33337
                  • 3,975 Posts
                  Elements -> Manage Elements -> Plugins
                    Zaigham R - MODX Professional | Skype | Email | Twitter

                    Digging the interwebs for #MODX gems and bringing it to you. modx.link
                    • 11650
                    • 15 Posts
                    Oh! Nifty...I’ll take a look at this now and let you guys know if I get this to work.
                      • 28042 ☆ A M B ☆
                      • 24,524 Posts
                      I found that article on google yesterday, but the admin panel looks nothing like that.
                      Page updated.
                        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