0

如何在输入 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();
    }

日菜单.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();
    }   
}
4

0 回答 0