public function initialize() { $type = new Radio('type', ['1' => '单选/多选', '3' => '判断']); $type->setLabel('题目类型'); $type->addValidators([new PresenceOf(['message' => '题目类型必选'])]); $this->add($type); $question = new TextArea('question'); $question->setLabel('题目'); $question->addValidators([new PresenceOf(['message' => '题目内容必填'])]); $this->add($question); }
public function getGender() { $genders = array('male' => '男士', 'female' => '女士', 'other' => '其他'); $radios = array(); $user = $this->getModel(); foreach ($genders as $value => $label) { $radio = new Radio('gender', array('value' => $value)); $radio->setLabel($label); $radio->setDefault($user->gender); $radios[$value] = $radio; } return $this->gender = $radios; }
public function getIcons() { $icons = array('reminder' => 'Reminder', 'rumor' => 'Rumor', 'warning' => 'Warning'); $radios = array(); $news = $this->getModel(); foreach ($icons as $icon => $label) { $radio = new Radio('icon', array('value' => $icon)); $radio->setLabel($label); $radio->setDefault($news->icon); $radios[$icon] = $radio; } return $this->radio = $radios; }
function initialize($entity = null, $options = null) { $date = new Date('date_found'); $date->setLabel('Input Date Found'); $date->setFilters(array('striptags', 'string')); $this->add($date); /*====================== Number =====================*/ $number = new Text('number'); $number->setLabel('Input Number'); $number->setFilters(array('striptags', 'string')); $number->addValidators(array(new PresenceOf(array('message' => 'Number is required')))); $this->add($number); /*====================== Solved =====================*/ $isSolved = new Radio('is_solved', array('name' => 'is_solved', 'value' => '1')); $isSolved->setLabel('Is Solved'); $isSolved->addValidators(array(new PresenceOf(array('message' => 'Is solved is required')))); $this->add($isSolved); $isSolved2 = new Radio('is_solved2', array('name' => 'is_solved', 'value' => '0', 'checked' => TRUE)); $isSolved2->setLabel('Is Solved2'); $isSolved2->addValidators(array(new PresenceOf(array('message' => 'Is solved is required')))); $this->add($isSolved2); $systemId = new Select('system_id', Systems::find(), array('using' => array('id', 'name'), 'useEmpty' => true)); $systemId->setLabel('Select System'); $systemId->addValidators(array(new PresenceOf(array('message' => 'System is required')))); if ($entity) { $systemId->setDefault(array($entity->system_id)); } $this->add($systemId); $modulesId = new Select('modules_id', Modules::find(), array('using' => array('id', 'name'), 'useEmpty' => true)); $modulesId->setLabel('Select Modules'); $modulesId->addValidators(array(new PresenceOf(array('message' => 'Modules is required')))); if ($entity) { $modulesId->setDefault(array($entity->modules_id)); } $this->add($modulesId); /*===== Bug =============*/ $systemId = new Select('system_id', Systems::find(), array('using' => array('id', 'name'), 'useEmpty' => true)); $systemId->setLabel('Select System'); $systemId->addValidators(array(new PresenceOf(array('message' => 'System is required')))); if ($entity) { $systemId->setDefault(array($entity->system_id)); } $this->add($systemId); $description = new TextArea('description'); $description->setLabel('Input Description'); $description->addValidators(array(new PresenceOf(array('message' => 'Description is required')))); $this->add($description); $hidden = new Hidden('id'); if ($entity) { $hidden->setDefault(array($entity->id)); } $this->add($hidden); }