【发布时间】:2014-04-17 19:54:30
【问题描述】:
我正在开发一个 DropdownField 的子类,我试图将它与相应的 DrodownFieldData.ss 模板耦合,但没有成功。
- 我反复刷新缓存。
- 我删除了本地主机 (XAMPP) 上的缓存文件夹
- 我将模板移动到“简单”主题的不同位置:
/simple/templates、/simple/templates/forms、/simple/templates/Includes - 如您所见,模板名称没有下划线字符,据报道该字符会导致问题
我这样称呼它:
return $this->customise($properties)->renderWith('DropdownFieldData');
您还有其他想法可以尝试吗?
这是代码。它基本上是 DropdownField 的一个副本,略去了 Field 方法。
<?php
class DropdownFieldData extends DropdownField {
public function Field($properties = array()) {
$source = $this->getSource();
$options = array();
if($source) {
// SQLMap needs this to add an empty value to the options
if(is_object($source) && $this->emptyString) {
$options[] = new ArrayData(array(
'Value' => '',
'Title' => $this->emptyString,
));
}
foreach($source as $value => $title) {
$selected = false;
if($value === '' && ($this->value === '' || $this->value === null)) {
$selected = true;
} else {
// check against value, fallback to a type check comparison when !value
if($value) {
$selected = ($value == $this->value);
} else {
$selected = ($value === $this->value) || (((string) $value) === ((string) $this->value));
}
$this->isSelected = $selected;
}
$disabled = false;
if(in_array($value, $this->disabledItems) && $title != $this->emptyString ){
$disabled = 'disabled';
}
$options[] = new ArrayData(array(
'Title' => $title,
'Value' => $value,
'Selected' => $selected,
'Disabled' => $disabled,
));
}
}
$properties = array_merge($properties, array('Options' => new ArrayList($options)));
return $this->customise($properties)->renderWith('DropdownFieldData');
// return parent::Field($properties);
}
}
【问题讨论】:
-
您确认
$this->customise($properties)->renderWith('DropdownFieldData');甚至被执行了吗?也许你把它放在错误的地方?你能分享你的全部课程吗? -
我编辑了我的帖子以包含课程代码。症状仍然存在。
-
谁对我的问题投了反对票,愿他们有勇气解释原因。
-
哈哈,显然他/她没有。我看到他/她再次删除了反对票:D
-
关于您的问题,我将在今天某个时候在本地测试环境中尝试您的代码。您能否还包括您正在使用的模板代码和您使用的文件名?