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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

weird non redirect issues


Go to End


2 Posts   936 Views

Avatar
mattclegg

Community Member, 56 Posts

22 March 2010 at 2:57pm

Edited: 22/03/2010 2:58pm

Hi,

Im using a lookup function to get a relevant object by ID like;

$val=(search string as integer);

$sqlQuery = new SQLQuery("COUNT(myObject.ID)","myObject","ID=".intval($val));
if($sqlQuery->execute()->value()){
return DataObject::get_by_id('myObject', intval($val));
}else{
Director::redirect('/myObjectSearchPage/');
}

but instead of being redirected the function is returning null and I get;

[Notice] Trying to get property of non-object

Any ideas?

Avatar
Hamish

Community Member, 712 Posts

22 March 2010 at 3:16pm

Edited: 22/03/2010 3:21pm

EDIT: misread the question, let me try again:

Why are you running an SQL Count query? The following makes a lot more sense:

if($object = DataObject::get_by_id('myObject', intval($val)))
	return $object;
else
	Director::redirect('/myObjectSearchPage/'); 

The error is probably being caused in whatever method is calling the above code. It should check that a valid object is returned. Note that Director::redirect doesn't halt execution - so you still need to check if the method has returned a valid object before doing something with it.