I had 2 issues with your example BobRay, but it helped point me in the right direction. Thank you.
I pulled that code into a snippet and tried to echo the results and came out with two different errors:
Call to a member function getOne() on a non-object
Fixed by changing $parentObj to $parent
Call to a member function get() on a non-object
Fixed by changing defining explicitly what context I was working in:
$parent= $resource->getOne('Parent');
/* the 'if' statement keeps it from crashing when run for docs at the root with no parent */
if ($parent) {
$parentId = $parent->get('id');
$parentAlias = $parent->get('alias');
}
if ($parentId == '82') {
$resource->set('context_key', 'web');
$alias = $resource->get('alias');
$resource->set('uri_override', '1');
$resource->set('uri', $parentAlias.'/topics/'.$alias);
$resource->save();
}
I'm not sure if this would cause any other conflicting issues or reveals issues with my security layer, but it works for me now. I effectively get the folder structure /topics/cat-1 to rewrite as /cat-1/topics.
A full explanation of my purpose for doing this is below, in case others find it interesting:
I'm working on setting up a blog, but I didn't want to do it the standard way of having a /blog sub-directory and store all my posts there. I have resources such as web-design, seo, graphic-design and want to experiment with running my blog posts through those containers. The problem is, it then becomes all decentralized and more difficult to manage.
This workaround above, with some help from my htaccess for redirecting purposes, allows me to store all my blog posts in my container folder /topics, while still maintaining my structure around my services. When I write about web design, instead of having www.domain.com/topics/web-design-post.. I can give my web design keyword a bit more weight having posts going through www.domain.com/web-design/topics/web-design-post or www.domain.com/web-design/web-design-post (which I'll likely switch it to instead).
It might not be the most elegant way to do this (for example tagging the posts would probably be better and then rewrite the URI), but it works for my purposes as I won't be changing categories often.