1778 Posts in 581 Topics by 555 members
| Go to End | ||
| Author | Topic: | 3192 Views |
-
Re: Different field types in Create Page form

17 March 2009 at 4:36am
To work with Silverstripe, you need to be kiinda' comfortable with OO and MVC patterns ...
I will try to take a better look at the tutorials.... and OO and MVC. Thanks a lot for your patience
<?php
class Blabla extends Page {public static $db = array(
'Companies' => 'Text'
);function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Companies', new OptionsetField('Companies', '', $DataObjectSet->toDropDownMap('id','name')));return $fields;
}
}
class Blabla_Controller extends Page_Controller {
public function init() {
parent::init();
}
?>flushing dies (no error but nothing after GhostPage)
Victor
-
Re: Different field types in Create Page form

17 March 2009 at 5:12am
Yeah.. it isn't working code... Just a quick example to get the gist of it ...
But other than a Curly bracket and some other source data ... it should work ...
-
Re: Different field types in Create Page form

17 March 2009 at 5:27am
OK, I will try to make it work. Thanks: it points me in some direction
-
Re: Different field types in Create Page form

18 March 2009 at 12:20am Last edited: 18 March 2009 12:21am
OK, I almost got it
<?php
class TestPage extends Page {
static $db = array(
"Method" => 'Text'
);
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.Main", new DropdownField("Method", "Select Method", array(
'First','Second'
)));
return $fields;
}
}class TestPage_Controller extends Page_Controller {
}
?>It stores, however, numerical values 0,1 instead of labels First, Second.
-
Re: Different field types in Create Page form

18 March 2009 at 12:30am Last edited: 18 March 2009 12:31am
Yeah..
change :
array(
'First','Second'
);into something like
array(
'Key'=>'value',
'Key'=>'value'
);and it will store your key..
-
Re: Different field types in Create Page form

18 March 2009 at 1:14am Last edited: 18 March 2009 1:49am
Thanks! This works (on the contrary to recommended on the tutorial page to store PageColor). So finally working code (in case someone else needs it):
<?php
class TestPage extends Page {
static $db = array(
"Method" => 'Text'
);
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.Main", new DropdownField("Method", "Select Method", array(
'First'=>'First Method',
'Second' =>'Second Method'
)));
return $fields;
}
}class TestPage_Controller extends Page_Controller {
}
?>
| 3192 Views | ||
| Go to Top |


