We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 53573
    • 10 Posts
    MODX Version: MODX Revolution 2.5.7

    Hi,

    Just wondered if anyone could help in the correct way when dealing with custom routes that should display data from a custom table and also have access to modx chunks, modx snippets etc. I already know how to display custom data from snippets.

    creating routes is straightforward with MODX Driven content:

    wwww.example.com/news - displays list of news content in cms
    wwww.example.com/news/some-news-story - single news page generated in cms
    wwww.example.com/news/some-news-story-2 - single news page generated in cms


    However I was unsure the correct way when it comes to custom generated data:
    wwww.example.com/results - displays list of results which when clicked will take you to result article from custom table
    wwww.example.com/results/1 - single result page generated from custom table
    wwww.example.com/results/2 - single result page generated from custom table


    Is it the case am meant to create a dummy cms page to and than use query strings:
    wwww.example.com/results - cms page load custom data from snippet
    wwww.example.com/results?id=1 - if id 1 exists load custom data else return 404


    Or is there a much better method that I missed in Docs/Forum?

    Thank you




    This question has been answered by Jako. See the first response.

      • 46886
      • 1,154 Posts
      However I was unsure the correct way when it comes to custom generated data:

      I think for this, you mean a snippet is generating the data, right? For a custom table, I think you might use MIGX.
      • discuss.answer
        Take a look on the CustomRequest extra.
          • 3749
          • 24,544 Posts
          It sounds to me like you don't really want custom routes, but rather a way to present custom data based on the URL.

          It usually makes things easier and more efficient if you can create a custom snippet that looks at the query string and presents the appropriate data. That way you only have one page to update and maintain.
            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
            • 53573
            • 10 Posts
            Quote from: Jako at Nov 12, 2018, 04:20 PM
            Take a look on the CustomRequest extra.

            Hey Jako,

            That plug-in seems exactly what am looking for smiley, However I can't seem to get it to work, I tried a simple configuration as follows:

            Configuration Name
            results

            Alias Path
            results(from selected resource created and published)

            URI Parameter
            ["parameter1", "parameter2"]

            I tried
            wwww.example.com/results
            wwww.example.com/results/1
            wwww.example.com/results/1/2
            wwww.example.com/results.html

            Also changed customrequest.debug to true but no errors just returns 404

            Any ideas as you the creator wink

            • Try wwww.example.com/results/1.html
                • 53573
                • 10 Posts
                Quote from: Jako at Nov 12, 2018, 08:00 PM
                Try wwww.example.com/results/1.html

                Sadly still returns 404 but there is an error in the log

                \core\model\modx\modx.class.php : 1613) [OnPageNotFound]string
                • It should work that way.

                  I have updated the package for logging the found configuration together with the additional request parameters set by that configuration. The log level for invalid configurations is changed from info to error in debug mode, so you should notice those issues.
                    • 53573
                    • 10 Posts
                    Quote from: Jako at Nov 13, 2018, 11:06 AM
                    It should work that way.

                    I have updated the package for logging the found configuration together with the additional request parameters set by that configuration. The log level for invalid configurations is changed from info to error in debug mode, so you should notice those issues.

                    Actually I found what the issue is:

                    my site directory file path
                    C:\wamp\www\sites\example

                    browser url using to test plug-in
                    http://localhost/sites/example/results

                    alias setting used in plug-in
                    results

                    So $search variable is returning
                    "sites/example/results"
                    and $request['alias'] is returning just
                    "results"

                    so this part of code would always return false as no match
                    0 === strpos($search, $request['alias'])


                    by changing alias in plug-in to sites/example/results it now works

                    Is it possible to update the plug-in to handle this issue? as that means if you change your directory or when moving servers your have to update all your configuration settings for the plug-in.

                    Thanks
                    • The plugin uses the default modx routing settings for locating the alias. You have to set base_url system setting (or context) right, then it won't get the wrong value there.