17487 Posts in 4473 Topics by 1978 members
|Go to End|
3 June 2008 at 7:09pm
I've tried static $defaults = array ('Title' => 'DefaultValue');
but it doesn't seem to work. I also attempted to use onBeforeWrite(), but this is upon saving, not upon creating the actual new Page.
is there some simple way to do this?
3 June 2008 at 7:53pm
$defaults is the correct way to do it. Does the space between array ( ) make a difference? rather then array()??
20 June 2008 at 5:49am
no, that doesn't work. i've drop the table and tried it over and over again.
here's the code:
static $db = array(
'Title' => 'Varchar(150)',
'Teaser' => 'Text',
'MemberPrice' => 'Currency',
'GenPrice' => 'Currency',
'TicketLinkText' => 'Varchar(60)',
'TicketLinkURL' => 'Varchar(255)'
static $defaults = array('TicketLinkText' => 'Buy Tickets');
and when creating this database i get:
# Table SubSeries: created
# Field SubSeries.ClassName: created as enum('SubSeries') character set utf8 collate utf8_general_ci default 'SubSeries'
# Field SubSeries.Created: created as datetime
# Field SubSeries.LastEdited: created as datetime
# Field SubSeries.Title: created as varchar(150) character set utf8 collate utf8_general_ci
# Field SubSeries.Teaser: created as mediumtext character set utf8 collate utf8_general_ci
# Field SubSeries.MemberPrice: created as decimal(9,2)
# Field SubSeries.GenPrice: created as decimal(9,2)
# Field SubSeries.TicketLinkText: created as varchar(60) character set utf8 collate utf8_general_ci
# Field SubSeries.TicketLinkURL: created as varchar(255) character set utf8 collate utf8_general_ci
# Field SubSeries.ImageID: created as int(11) not null default '0'
# Field SubSeries.LocationID: created as int(11) not null default '0'
# Index SubSeries.ImageID: created as (ImageID)
# Index SubSeries.LocationID: created as (LocationID)
# Index SubSeries.ClassName: created as (ClassName)
but no default is set.
any help would be great. thanks!
20 June 2008 at 7:23am
The default doesn't get set in the database. Does creating a new page have the default set?
1 July 2008 at 5:41am
no it doesn't fill out any fields.
the issue could be that this is a dataobject and not a page. Do you think thats the problem, and if so, is there a way to set defaults for data objects?
7 July 2008 at 2:55pm
$defaults doesn't affect the MySQL database default; it sets default values when you create new DataObjects. It works for DataObject as well as SiteTree.
Make sure that when you're creating the new DataObject, you're not passing any arguments to the constructor. The array argument for setting DataObject's fields should only be used when creating existing database records from the database. Because it's designed for that, it bypasses the populateDefaults() method that sets defaults.
|Go to Top|