2012-04-22 110 views
1

打破这是的示例代码引用字段一个简​​单的重新写入:敏捷工具包4.2 ...引用字段类型与模型

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中\窗体/ Field.php:652 [2]用htmlspecialchars()预计参数1是字符串,Field.php

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'); 
    } 
给出

综观代码,围绕线648阵列

确实很明显是创建$ descr作为($ value,descr)的一个数组。

这是一个bug还是我脱离基地。谢谢。

回答

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()) 
      ; 
    } 
} 
  1. 注重addField("Dropdown")
  2. 使用setModel而非setValueList($model);
+0

你有没有测试过这个? 它不适用于表格模型。 类Form_Field_ValueList定义了只包含以下代码的setModel()方法:$ this-> setValueList(array('foo','bar')); – 2012-05-14 17:06:36

+0

它是getValueList()方法,然后对事物进行排序。 – jancha 2012-05-15 21:10:03

+0

我不明白你的评论,setModel函数只是调用超级方法,然后将值列表设置为foo,bar。下拉列表中不包含任何内容。 – 2012-05-16 13:23:41