我是concrete5和PHP的新手。
DB.XML
<!-- features for Row 1 -->
<field name="PC_Row_1_Feature_1_Enabled" type="L">
<default value="0" />
<unsigned/>
</field>
<field name="PC_Row_1_Feature_2_Enabled" type="L">
<default value="0" />
<unsigned/>
</field>
<field name="PC_Row_1_Feature_3_Enabled" type="L">
<default value="0" />
<unsigned/>
</field>
<field name="PC_Row_1_Feature_4_Enabled" type="L">
<default value="0" />
<unsigned/>
</field>
<!-- features for Row 2 -->
<field name="PC_Row_2_Feature_1_Enabled" type="L">
<default value="0" />
<unsigned/>
</field>
<field name="PC_Row_2_Feature_2_Enabled" type="L">
<default value="0" />
<unsigned/>
</field>
<field name="PC_Row_2_Feature_3_Enabled" type="L">
<default value="0" />
<unsigned/>
</field>
<field name="PC_Row_2_Feature_4_Enabled" type="L">
<default value="0" />
<unsigned/>
</field>
edit.php
<?php
echo $form->checkbox("PC_Row_1_Feature_1_Enabled", 1, $PC_Row_1_Feature_1_Enabled);
?>
<?php
echo $form->checkbox("PC_Row_1_Feature_2_Enabled", 1, $PC_Row_1_Feature_2_Enabled);
?>
<?php
echo $form->checkbox("PC_Row_1_Feature_3_Enabled", 1, $PC_Row_1_Feature_3_Enabled);
?>
<?php
echo $form->checkbox("PC_Row_1_Feature_4_Enabled", 1, $PC_Row_1_Feature_4_Enabled);
?>
<?php
echo $form->checkbox("PC_Row_2_Feature_1_Enabled", 1, $PC_Row_2_Feature_1_Enabled);
?>
<?php
echo $form->checkbox("PC_Row_2_Feature_2_Enabled", 1, $PC_Row_2_Feature_2_Enabled);
?>
<?php
echo $form->checkbox("PC_Row_2_Feature_3_Enabled", 1, $PC_Row_2_Feature_3_Enabled);
?>
<?php
echo $form->checkbox("PC_Row_2_Feature_4_Enabled", 1, $PC_Row_2_Feature_4_Enabled);
?>
我也尝试过:
echo $form->checkbox('PC_Row_1_Feature_3_Enabled', $PC_Row_1_Feature_3_Enabled, false);
还认为也许一点JS会帮助
$('.checkbox input').on('click',function(){
if($(this).val() == "0"){
$(this).val('1');
$(this).prop('checked', true);
} else {
$(this).val('0');
$(this).prop('checked', false);
}
});
要更改值并取消选中等…
view.php
<?php if($PC_Row_2_Feature_1_Enabled == "1") { ?>
<img class="ui centered image" src="<?php echo $this->getThemePath() ?>/images/tick_mark.png">
<?php } ?>
我遇到的问题是,当我选中或取消选中时,它不会在数据库中发生变化,也不会在视图中显示或隐藏。我知道我可能做错了什么,所以希望有具体经验的人能帮我一把。
要保存复选框值,请检查是否已在块控制器.php save()方法中设置了键。save()方法允许在保存到数据库之前更改$_POST数组数据(例如,如果要修剪()输入)。
示例:
public function save($args)
{
$args['checkbox_example'] = isset($args['checkbox_example']) ? 1 : 0;
parent::save($args);
}
$args是$_POST数组。
- 如果设置了checkbox_example键,则该值设置为1
- 如果未设置checkbox_example键,则该值将设置为0