1999 Posts in 530 Topics by 433 members
E-Commerce Modules
SilverStripe Forums » E-Commerce Modules » Call to a member function toDropDownMap() on a non-object in ... Product.php
Discuss about the various e-commerce modules available:
Ecommerce, SS Shop, SilverCart and SwipeStripe
Alternatively, have a look the shared mailinglist.
Moderators: martimiz, Nicolaas, Howard, Sean, Ryan M., biapar, Willr, Ingo, Jedateach, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 2311 Views |
-
Call to a member function toDropDownMap() on a non-object in ... Product.php

19 June 2009 at 4:56pm
Dear All,
I've tried google around but i've found no solution to creating a dropdown list with a DataObject::get()
The background is that i'm trying to set up a store to show which district(area) is my product is located. This is what i've done.
<?php
class District extends DataObject {
static $db = array(
'Name' => 'Varchar(50)',
);static $has_one = array(
'StateID' => 'State'
);
}
?>also a State DataObject
<?php
class State extends DataObject {
static $db = array(
'Name' => 'Varchar(50)'
);}
?>Then i want it shows up as a pull down menu in my Product, so i did this in Product.php's getCMSFields()
function getCMSFields() {
$fields = parent::getCMSFields();...
//Database request for the object
$myDataSet = DataObject::get("District");
# if($myDataSet){
// This returns an array of ID => Title
$map = $myDataSet->toDropDownMap();$fields->addFieldToTab("Root.Content.Main", new ListboxField(
'District',
'District',
$map,
$map[0])
);
# }
...
return $fields;
}But DataObject::get("District"); gives me null, it seems that Product.php cannot access the District object.
It seems my O-O concepts are really bad, can anyone give me a hand?
Thanks in advance!
-
Re: Call to a member function toDropDownMap() on a non-object in ... Product.php

19 June 2009 at 5:30pm
Well, probably you forgot to set up the other end of the relation in your Product.php, like so for instance (if you use a has_many):
public static $has_many = array(
'District' => 'District'
);and in toDropDownMap you might want to add:
$map = $myDataSet->toDropDownMap('ID', 'Name');
See also:
http://doc.silverstripe.com/doku.php?id=tutorial:5-dataobject-relationship-management
and
http://doc.silverstripe.com/doku.php?id=optionsetfield&s=todropdownmap
Helps?
-
Re: Call to a member function toDropDownMap() on a non-object in ... Product.php

19 June 2009 at 6:08pm
Thanks for the prompt reply.
Well... i did actually declare
static $has_one = array(
'Image' => 'Product_Image',
'District' => 'District'
);But Product stilll can't access to DataObject::get("District").
I'll go thru the http://doc.silverstripe.com/doku.php?id=tutorial:5-dataobject-relationship-management tutorial. I'll post my results if i get it right.
| 2311 Views | ||
|
Page:
1
|
Go to Top |

