1149 Posts in 2553 Topics by 408 members
|Go to End|
10 December 2010 at 6:10am
I just upgraded to 2.4.3 from 2.3.* and, as we know, with the advent of hierarchical URLs, URLSegment can no longer be used as a link since the nesting is not stored in that field. I realize that this was considered bad practice in the first place, but perhaps had I known how to convert a URLSegment TO a Link() in the first place then I wouldn't have done it ;)
That said, let's get to it. I use a lot of custom queries on my site using DB::query() and SQLQuery(). In these queries, the Link() function is meaningless. So I am getting the URLSegment from the SiteTree table and then just using that value as the Link. Now, as stated above, this doesn't work, because these pages are now nested within other parent pages.
I need to know how I can "calculate" the FULL URL from this URLSegment, much like the redirects performed by the MigrateSiteTreeLinkingTask action does. There has to be a method for this, but I haven't found it yet. Any help out there?
Thanks in advance,
10 December 2010 at 12:09pm
Well like you said you should be using $Link in templates etc. It looks like SiteTree's RelativeLink() function handles making the full link. You will still need to get the actual object record to call that though. AFAIK there doesn't appear to be a static function to 'convert' foo/ to /about-us/foo without orignally having the foo page object (i.e dataobject::get()) to start with.
The MigrateSiteTreeLinking doesn't actually rewrite the URL, it saves the ID then on output it renders the Link() function of the page.
11 December 2010 at 5:39am
Thanks for your reply @willr. How do you recommend getting the object record from the URLSegment?? Or, the ID. I can get the ID in my query, obviously. I guess you're saying use DataObject::get_by_id() and then pass that result to RelativeLink()?
|Go to Top|