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.

Upgrading SilverStripe

Ask questions about upgrading SilverStripe to the latest version.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

From 2.3.1 to 2.3.2 error on URLSegment


Reply

5 Posts   1037 Views

Avatar
biapar

24 June 2009 at 1:31am Forum Moderator, 435 Posts

After Upgrade from 2.3.1 to 2.3.2 I've error caused by this function in page.php of mysite:

function GetLinkFromID($id = 1) {
$do = DataObject::get_one('Page', '`SiteTree_Live`.ID = '.$id, true);
return ($do->URLSegment); <-- here

Error:
[Notice] Trying to get property of non-object

Avatar
Hamish

24 June 2009 at 9:01am Community Member, 712 Posts

Are you sure the upgrade caused it?

The error means that there is no page record with the id. You should make the function safer by changing it to:

function GetLinkFromID($id = 1) {
   $do = DataObject::get_one('Page', '`SiteTree_Live`.ID = '.$id, true);
   return $do ? $do->URLSegment : false;

This way, if there is not page with that id, it will return false instead of trying to access a member of the nonexistent object.

Avatar
biapar

24 June 2009 at 8:55pm Forum Moderator, 435 Posts

I've update SS production installation and there is page with ID = 1.
Before updating, it work.

Best Regards

Avatar
Hamish

25 June 2009 at 9:20am Community Member, 712 Posts

Well this: "'`SiteTree_Live`.ID = '.$id" is not returning anything.

Maybe the field SiteTree_Live changed?

Avatar
ajshort

25 June 2009 at 9:22am Community Member, 244 Posts

You shouldn't be querying form the Live table - instead you should just do "`SiteTree`.`ID` = $ID" and your query will automatically be rewritten if you are getting data from the Live table.