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.

Archive

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

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

Fatal error: Call to a member function enumValues() on a non-object


Reply

5 Posts   1572 Views

Avatar
ojalà

17 October 2008 at 7:39pm Community Member, 87 Posts

Hi!
I try to use select form as explain in guide but I have this error:

Call to a member function enumValues() on a non-object in E:\_silverstripe_cms\itesa\mysite\code\Page.php on line 51

Why?

Avatar
Sean

17 October 2008 at 10:26pm (Last edited: 17 October 2008 10:27pm), Forum Moderator, 921 Posts

What guide? Where?

What is on that line in the Page.php file as the debug error explains?

Sean

Avatar
ojalà

17 October 2008 at 10:50pm Community Member, 87 Posts

in my page.php , under the page controller I put this function

function DropForm{
$field = new DropdownField(
'Country',
'Country',
singleton('MyObject')->dbObject('Country')->enumValues()
);
}

and I create MyobjectField.php with this class

class MyObject extends DataObject {
static $db = array(
'Country' => "Enum('New Zealand,United States,Germany','New Zealand')"
);
}

Avatar
ojalà

17 October 2008 at 10:51pm Community Member, 87 Posts

the guide id here: http://doc.silverstripe.com/doku.php?id=dropdownfield

Avatar
Sean

18 October 2008 at 9:45am (Last edited: 18 October 2008 9:45am), Forum Moderator, 921 Posts

MyobjectField.php MUST have a class inside called "MyobjectField". If this isn't the case, SS will not detect the class.

In your case, just rename MyobjectField.php to MyObject.php, run ?flush=1 and you're set.

Sean