We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • I actually really understand the need for multiple table joins - I needed that for the site that I developed this component for. However, try as I might, I could not think of a SIMPLE way to do this that would be flexible enough for all situations - especially not when the "extra column and makeUrl" strategy is so much simpler and more flexible. The configuration for it alone would add way too much complexity, and I would probably need to add some sort of caching. And CustomUrls can also generate, auto-detect, and redirect to schema urls, all of which will need to be modified to work with joins.

    This means that I (or someone else) might add joined tables to the component in the future, or at least a dedicated alias table, but in the meantime it will have to stay one table only. If anyone wants to contribute, feel free to do so on GitHub smiley.

    So everything went flawlessly while working with one table. I’m stuck when it comes to deal with multiple tables. Should i generate multiple settings or should i use the child_schemas setting ? I guess my case is almost the same as Lucas, i have only one schema with multiple tables

    To set up child schemas, you have to set them up as independent schemas, then list their names (and optionally an array of setting overrides) under their parent’s "child_schemas" setting. It can be a simple array of schema names or an array of "name" => "setting_overrides_array" pairs - here’s an example: [tt]..,"child_schemas": {"child1":{"url_prefix":""},"child2":{"url_prefix":""},},...[/tt]. If you list multiple children for one parent, they will be checked in sequence until a match is found. To CHAIN children, you will need to add children to the child (grandchildren). You also can set the "run_without_parent" setting to false if a schema only exists as a child of another schema. Please also get the latest GitHub source, since I made a few fixes to children and actions in particular.

    Right now, child schemas work completely independently of each other. In other words, they are designed to have multiple custom URL schemas working together (e.g. /author/topic/, /location/topic/, etc...). You can use them for something like /category/child, but the child would have to have a UNIQUE alias across all categories, and you would need to validate it somehow to make sure that the child matches the category. Right now this plugin is really only designed to work with UNIQUE aliases, not those dependent on joins.

    To illustrate with an example:

    You have a table of articles, each categorized to a topic, author, country, state, and city. You would use TWO schemas (parent and child) when you are displaying a list of articles filtered by BOTH topic and author: http://site.com/author/topic/. The REQUEST parameters ’author_id’ and ’topic_id’ will be set on the page, and it is up to you to figure out if any articles match and what to do if they don’t. Similarly, you would use THREE schemas (parent, child, grandchild) if you need http://site.com/country/author/topic/.

    However, if you try to do this with http://site.com/country/state/city/topic/, you must use only TWO schemas (city and topic), because the same city name is present in different states. Otherwise, if your country is United States and your state is New York, you might get Small Town, AZ instead of Small Town, NY. You will need to GENERATE an alias for Small Town as follows: "united-states/new-york/small-town" and use the CITY table for the parent schema, and the TOPIC table as the child schema, to get something like http://site.com/united-states/new-york/small-town/some-topic/ and the following REQUEST parameters set: ’city_id’ and ’topic_id’.

    Finally, to display the individual article (whether or not you use topics, locations, or authors in the URL), make sure each article has a UNIQUE alias, even if you have to generate a "country/state/city/topic/author/article-name" alias every time your article is edited. Alternatively, you can just make sure the article alias is unique in some other way (such as by appending the createdon date or article id) and proceed to use child schemas for the complex URL, although that would not be very efficient.

    Does that answer your question?
      WebsiteZen.com - MODX and E-Commerce web development in the San Francisco Bay Area
    • Oleg,

      Once again much thanks for your clear explanations. I think i now have the whole picture of how your plugin works (and how i should define my schemas to fulfill my needs)
      • Here is the site that I built this for: http://tiklar.com. This has CustomURLs for cities, regions, countries, topics, articles, users, and several combinations of the above.
          WebsiteZen.com - MODX and E-Commerce web development in the San Francisco Bay Area
          • 41874
          • 33 Posts
          Hi Oleg,

          I tried to setup your component, but it won't work for me. First of all, is it necessary to install UserUrls next to the files from customurls?

          I've tried your simple steps in reply #9. I'm running modx v2.2.8-pl. Using FURLs alias path (full path in url). eg: /home/page

          The title and debug calls are both in resource 32. Resource 32 has an alias called 'page', its parent is resource 4 with alias 'home'. The debug snippet works when navigating to /home/page. However, navigating to /home/page/[name] gives a 404 page.

          I grabbed the most recent files from Github and used the schemas from above (#9) (including adapting landing resource id to 32).

          What can I do to get it working?


          Many thanks in advance!

          Huub
            I love flexibility
          • You do not need to have UserUrls installed. The default configuration is simply supposed to "replace" UserUrls.

            Take a look at the configuration options in the $defaults array at https://github.com/yoleg/CustomUrls/blob/master/core/components/customurls/model/customurls/customurls.class.php. You can change them in the JSON setting arrays of the two settings.

            For example, you may want to set the landing_resource_id setting to the ID number of the landing page and the url_prefix to "/home/page".

            To clarify, the plugin does NOT use the alias of existing resources in the URL. Instead, it uses a hard-coded prefix configured with the "url_prefix" setting.
              WebsiteZen.com - MODX and E-Commerce web development in the San Francisco Bay Area
              • 46315
              • 30 Posts
              Hi Oleg

              I'm quite new to coding so this may be a very newby question.

              I'd like to know if it is possible to create a "custom" friendly URL using customUrls like:

              from: domain.com/index.php?id=18&Pref=R1234 - FURL version: domain.com/product/?Pref=R1234

              to: domain.com/product/a-must-have-product/R1234 (or similar)

              I'm pulling data from a custom table via a query string parameter(Pref).

              Thanks in advance