Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo

Unigue URL Segment in SiteTree::write()


Go to End


2 Posts   2929 Views

Avatar
xmedeko

Community Member, 94 Posts

6 August 2007 at 5:49pm

Hi,
I made a page "My 2nd Page" and my URLSegment was "my-2nd-page", then I have duplicated this page, and my URL segment has been changed to "mynd-page-2" (wrong). I made the patch:

--- SiteTree.php.orig	2007-08-06 17:48:37.000000000 +1200
+++ SiteTree.php	2007-08-06 17:47:06.000000000 +1200
@@ -419,7 +419,7 @@
 		$count = 1;
 		while(DataObject::get_one("SiteTree", "URLSegment = '$this->URLSegment' $idFilter")) {
 			$count++;
-			$this->URLSegment = ereg_replace('-[0-9]+','', $this->URLSegment) . "-$count";
+			$this->URLSegment = ereg_replace('-[0-9]+$','', $this->URLSegment) . "-$count";
 		}
 		
 		// If the URLSegment has been changed, rewrite links

And then duplication made URLSegment "my-2nd-page-2" (is that better?)

Avatar
Sean

Forum Moderator, 922 Posts

6 August 2007 at 10:15pm

That sounds good to me. I guess it was a miss that it did what it was originally doing, with a number already in the URL segment. Andy, could you make sure this is patched in the main branch? :-)

Sean