这是对参考字段的示例代码的简单重写:
class page_LoadResults extends Page {
function init(){
parent::init();
$p=$this;
$f=$p->add('Form');
$c=$p->add('Model_Season');
$f->addField('reference','Season')
->setValueList($c)
->validateNotNull()
->add('Icon',null,'after_field')
->set('arrows-left3')
->addStyle('cursor','pointer')
->js('click',$f->js()->reload())
;
调用时,我收到一条错误消息:
\ atk4 \ lib \ Form / Field.php:652 [2] htmlspecialchars()期望参数1为字符串,给定数组
查看代码,在Field.php的第648行附近
foreach($this->getValueList() as $value=>$descr){
// Check if a separator is not needed identified with _separator<
$output.=
$this->getOption($value)
.htmlspecialchars($descr)
.$this->getTag('/option');
}
确实显然是将$ descr创建为($ value,descr)
的数组这是一个错误还是我离开了基地。感谢。
答案 0 :(得分:2)
使用atk 4.2语法
<?php
class page_b extends Page {
function init(){
parent::init();
$p=$this;
$f=$p->add('Form');
$field = $f->addField('Dropdown','Season');
$field->setModel("a");
$field
->validateNotNull()
->add('Icon',null,'after_field')
->set('arrows-left3')
->addStyle('cursor','pointer')
->js('click',$f->js()->reload())
;
}
}
addField("Dropdown")
setModel
而不是setValueList($model);