<![CDATA[ CustomUrls - custom friendly urls for any database table(s) - My Forums]]> https://forums.modx.com/thread/?thread=32618 <![CDATA[Re: CustomUrls - custom friendly urls for any database table(s)]]> https://forums.modx.com/thread/32618/customurls---custom-friendly-urls-for-any-database-table-s?page=2#dis-post-498802
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]]>
bvirtual May 28, 2014, 07:42 AM https://forums.modx.com/thread/32618/customurls---custom-friendly-urls-for-any-database-table-s?page=2#dis-post-498802
<![CDATA[Re: CustomUrls - custom friendly urls for any database table(s)]]> https://forums.modx.com/thread/32618/customurls---custom-friendly-urls-for-any-database-table-s?page=2#dis-post-478030
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.
]]>
yoleg Sep 18, 2013, 02:35 AM https://forums.modx.com/thread/32618/customurls---custom-friendly-urls-for-any-database-table-s?page=2#dis-post-478030
<![CDATA[Re: CustomUrls - custom friendly urls for any database table(s)]]> https://forums.modx.com/thread/32618/customurls---custom-friendly-urls-for-any-database-table-s?page=2#dis-post-476744
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
]]>
hvoort Sep 04, 2013, 05:31 PM https://forums.modx.com/thread/32618/customurls---custom-friendly-urls-for-any-database-table-s?page=2#dis-post-476744
<![CDATA[Re: CustomUrls - custom friendly urls for any database table(s)]]> https://forums.modx.com/thread/32618/customurls---custom-friendly-urls-for-any-database-table-s?page=2#dis-post-393130 http://tiklar.com. This has CustomURLs for cities, regions, countries, topics, articles, users, and several combinations of the above.]]> yoleg Sep 12, 2011, 05:21 PM https://forums.modx.com/thread/32618/customurls---custom-friendly-urls-for-any-database-table-s?page=2#dis-post-393130 <![CDATA[Re: CustomUrls - custom friendly urls for any database table(s)]]> https://forums.modx.com/thread/32618/customurls---custom-friendly-urls-for-any-database-table-s?page=2#dis-post-179192
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)]]>
romain Jul 21, 2011, 04:58 PM https://forums.modx.com/thread/32618/customurls---custom-friendly-urls-for-any-database-table-s?page=2#dis-post-179192
<![CDATA[Re: CustomUrls - custom friendly urls for any database table(s)]]> https://forums.modx.com/thread/32618/customurls---custom-friendly-urls-for-any-database-table-s?page=2#dis-post-179191
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?]]>
yoleg Jul 21, 2011, 04:42 PM https://forums.modx.com/thread/32618/customurls---custom-friendly-urls-for-any-database-table-s?page=2#dis-post-179191
<![CDATA[Re: CustomUrls - custom friendly urls for any database table(s)]]> https://forums.modx.com/thread/32618/customurls---custom-friendly-urls-for-any-database-table-s#dis-post-179190 Just a small remark/question coming to my mind, how about generating some sitemap for those new pages ?
Edit: i guess writing a custom snippet should do the trick 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 :
<?xml version="1.0" encoding="UTF-8"?>
<model package="packageName" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" phpdoc-package="packageName">
    <object class="categoryClass" table="table_name" extends="xPDOSimpleObject">
     ...
    </object>

    <object class="childClass" table="table_name" extends="xPDOSimpleObject">
     ...
    </object>
</model>
]]>
romain Jul 21, 2011, 07:04 AM https://forums.modx.com/thread/32618/customurls---custom-friendly-urls-for-any-database-table-s#dis-post-179190
<![CDATA[Re: CustomUrls - custom friendly urls for any database table(s)]]> https://forums.modx.com/thread/32618/customurls---custom-friendly-urls-for-any-database-table-s#dis-post-179189
For multiple-schema setup, though, you will still need to write or generate a JSON array, which is simple enough (although tedious) to do by hand.

Here are basic instructions for GitHub:

1. Upload the "core" folder to the root of your installation.
2. Create a new plugin called CustomUrls. Copy the contents of the customurls.plugin.php file into the plugin contents (https://github.com/yoleg/CustomUrls/blob/master/core/components/customurls/elements/plugins/customurls.plugin.php). Set the plugin to the following events at your desired priority level: ’OnPageNotFound’,’OnLoadWebDocument’,’OnWebPagePrerender’. Save the plugin (and make sure it is not disabled).
3. Create a new snippet called "Debug". Copy the contents of debug.snippet.php into it and save it (https://github.com/yoleg/CustomUrls/blob/master/core/components/customurls/elements/snippets/debug.snippet.php).
4. Choose a resource (document) that will be the landing page for the schemaand paste "[[!Debug]]" into the content and "[[!+customurls.display]] Page" into the title. Set the alias to something unique (since it will be replaced everywhere on the page). Save it and remember the resource id.
5. System settings: Make sure friendly URLS are enabled and working. Create two system settings (type textarea) called "customurls.defaults" and "customurls.schemas".
6. customurls.defaults: create the defaults JSON array. Paste the following into customurls.defaults (and replace 21 with your landing resource id). Many of these defaults are not necessary or match the default values, but are included to show you how to add more settings in. More of the available default settings are in the customurls class (model/customurls/customurls.class.php). Remember to escape slashes, quotes, and brackets!:
{"landing_resource_id":"21","url_delimiter":"\/","set_get":true,"custom_search_replace":{"<meta name=\"robots\" content=\"noindex,nofollow\" \/>":"<meta name=\"robots\" content=\"index,follow\" \/>"},"run_without_parent":true,"search_where":[],"strict":true,"children_inherit_landing":true}

7. customurls.schemas: create your schemas JSON array. Paste the following into customurls.schemas (set for compatibility with UserUrls). :
{"users":{"request_prefix":"uu_","request_name_id":"userid"}}


That’s it! If you have any experience with UserUrls, these settings should have configured the familiar UserUrls site.com/username setup. Try it out by linking to a username and seeing what placeholders and parameters are being set on the page via the Debug snippet.

More example code:

If you need more than one schema (say, for a custom component called MyArticles). As you can see, each schema has a name ("users", "articles"...) and an array of settings that override the defaults.

{
    "users":{"landing_resource_id":"21","request_prefix":"uu_","request_name_id":"userid"},
    "articles":{
        "landing_resource_id":"22",
        "request_prefix":"article_",
        "request_name_id":"id",
        "load_modx_service":{"name":"myarticles","class":"MyArticles","package":"myarticles","config":[]},
        "search_class":"Article",
        "url_prefix":"articles\/",
        "search_field":"alias",
        "search_class_test_method":"canView"
    }
}


Here is the code I use to auto-generate my settings via an install script:
<?php
$output = '';
$url_settings['customurls.defaults'] = array(
    // PHP array of defaults
);
$url_settings['customurls.schemas'] = array();
$url_settings['customurls.schemas']['users'] = array(
    // PHP array of settings for the "users" schema
);
$url_settings['customurls.schemas']['articles'] = array(
    // PHP array of settings for the "articles" schema
);
    foreach ($url_settings as $key => $value) {
        $url_schemas_json = $modx->toJSON($value);
        $setting = $modx->getObject('modSystemSetting',$key);
        if ($setting === null) {
            $setting = $modx->newObject('modSystemSetting',array('key' => $key));
        }
        if ($setting !== null) {
            $setting->set('key',$key);
            $setting->set('value',$url_schemas_json);
            $setting->set('xtype','textarea');
            $setting->set('namespace','userurls');
            $setting->save();
            $output .= 'created setting '.$key.': '.htmlentities($url_schemas_json);
        }
    }
return $output;

]]>
yoleg Jul 20, 2011, 02:16 PM https://forums.modx.com/thread/32618/customurls---custom-friendly-urls-for-any-database-table-s#dis-post-179189
<![CDATA[Re: CustomUrls - custom friendly urls for any database table(s)]]> https://forums.modx.com/thread/32618/customurls---custom-friendly-urls-for-any-database-table-s#dis-post-179188
While this looks awesome i’m lacking some knowledge/vocabulary to start using it. It would be kind if anyone could provide a basic "step-by-step" to set this up (learning from example is far more easy for me - i guess for some others too).
Much thanks wink]]>
romain Jul 20, 2011, 03:40 AM https://forums.modx.com/thread/32618/customurls---custom-friendly-urls-for-any-database-table-s#dis-post-179188
<![CDATA[Re: CustomUrls - custom friendly urls for any database table(s)]]> https://forums.modx.com/thread/32618/customurls---custom-friendly-urls-for-any-database-table-s#dis-post-179187 Thanks so much for the detailed response... this is a really useful plugin!]]> okyanet Jul 19, 2011, 04:14 AM https://forums.modx.com/thread/32618/customurls---custom-friendly-urls-for-any-database-table-s#dis-post-179187