Php 混凝土5形式->;复选框工作不正常

Php 混凝土5形式->;复选框工作不正常,php,jquery,concrete5,Php,Jquery,Concrete5,我对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="

我对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>
我还认为也许一点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 } ?>

getThemePath()?>/images/tick_-mark.png“>

我遇到的问题是,当我选中或取消选中时,它在数据库中不会更改,然后在视图中也不会显示或隐藏。我知道我可能会做错什么,所以希望有具体经验的人能帮我一把。

要保存复选框值,请检查是否在块控制器中设置了键。php save()方法。save()方法允许在保存到数据库之前更改$\u POST数组数据(例如,如果您想修剪()输入)

例如:

public function save($args)
{
    $args['checkbox_example'] = isset($args['checkbox_example']) ? 1 : 0;
    parent::save($args);
}
$args是$\u POST数组

  • 如果设置了复选框\示例键,则该值设置为1
  • 如果未设置复选框示例键,则该值将设置为0
<?php if($PC_Row_2_Feature_1_Enabled == "1") { ?>
    <img class="ui centered image" src="<?php echo $this->getThemePath() ?>/images/tick_mark.png">
<?php } ?>
public function save($args)
{
    $args['checkbox_example'] = isset($args['checkbox_example']) ? 1 : 0;
    parent::save($args);
}