Here is a first silverstripe tutorial
- PHP :
- create a new page type for holding coniguration values. add any field you like
(file : mysite/code/ConfigPage.php ). Here we have added an image <?php class ConfigPage extends SiteTree { static $icon = "tutorial/images/treeicons/news"; static $db = array( ); static $has_one = array( 'Photo1' => 'Image' ); function getCMSFields() { $fields = parent::getCMSFields(); $fields->addFieldToTab('Root.Content.Main', new ImageField('Photo1'), 'Content'); return $fields; } static $defaults = array( 'ShowInMenus' => false ); } class ConfigPage_Controller extends ContentController { function init() { parent::init(); } ?>
- add the config function in your Page Controller ( mysite/code/Page.php) :
function Config( ) { $config = DataObject::get_one("ConfigPage"); return $config; }
- TEMPLATE : place the values in your templates where desired
example : <% control Config %> $Title $Photo1 <% end_control %> - WEB : rebuild database (/db/build?flush=1)
- ADMIN : create a new Config Page and set up values
|