Silverstripe动态地将对象添加到dataobject

时间:2014-01-06 13:19:53

标签: add silverstripe data-objects

如何在输入cms时动态地将数据添加到数据对象?

所以我需要知道如何在加载cms(SS 2.4)

时执行一个函数

感谢您的帮助。直到。

我想添加5个条目,如:

$curDate = date("Y-m-d");
for($i=0; $i< 5; $i++){

        $newDayMenue = new DayMenue;
        $newDayMenue->Date = $curDate;
        $newDayMenue->write();
    }

DayMenue.php:

class DayMenue extends DataObject {
    static $db = array(
        'Date' => 'Date'
    );

    static $has_one = array(
        'DayMenueHolder' => 'DayMenueHolder'    
    );


    static $many_many = array(
        'Foods' => 'Food'
    );



    function getCMSFields_forPopup() {
        $foods = DataObject::get('Food');

            $dateField = new DateField('Date', 'Datum');
            $dateField->setConfig('showcalendar', true);

        $fields = new FieldSet();

        $fields->push($dateField);
        if($foods){
        $fields->push(new CheckboxSetField('Foods', '', $foods->toDropDownMap('ID', 'Titel')));
        }

        return $fields;
    }

    function getMyDate() { 
        return $this->obj('Date')->Nice_Weekday();
    }   
}

0 个答案:

没有答案