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.

Form Questions /

Different field types in Create Page form


Go to End
Reply


14 Posts   4172 Views

Avatar
Victor

Community Member, 128 Posts

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

Avatar
Fuzz10

Community Member, 787 Posts

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 ...

Avatar
Victor

Community Member, 128 Posts

17 March 2009 at 5:27am

OK, I will try to make it work. Thanks: it points me in some direction

Avatar
Victor

Community Member, 128 Posts

18 March 2009 at 12:20am

Edited: 18/03/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.

Avatar
Fuzz10

Community Member, 787 Posts

18 March 2009 at 12:30am

Edited: 18/03/2009 12:31am

Yeah..

change :

array(
'First','Second'
); 

into something like

array(
'Key'=>'value',
'Key'=>'value'
);

and it will store your key..

Avatar
Victor

Community Member, 128 Posts

18 March 2009 at 1:14am

Edited: 18/03/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 { 
} 
?>

Go to Top