Add/Edit 表单上的 GC 自定义操作

GC Custom Action on Add/Edit Form

很好 day.Essentially,我正在尝试在 add/update 表单上添加一个自定义操作按钮。有没有一种方法可以创建一个仅在我单击不同于 "save and go back to list" 按钮的 "save" 按钮时触发的回调?

我不知道内置的方法,但你可以做以下(快速和肮脏的)事情来区分天气 "Save" 或 "Save and go back to list" 被点击:

以下步骤用于 flexgrid 主题和 ADD 操作。您应该根据您使用的主题调整代码,并为 EDIT 操作添加相同的代码。

首先,在文件中添加一个隐藏字段:

/assets/grocery_crud/themes/flexgrid/views/add.php

<input type="hidden" name="my_button_name" id="my_button_name" value="save" />

就在评论行上方:

<!-- End of hidden inputs -->

其次,转到/assets/grocery_crud/themes/flexigrid/js/flexgrid-add.js

并添加以下行:

$('#my_button_name').val("save_and_close");

就在下一行:

save_and_close = true;

只有单击 "Save and go back" 时,我们才会更新此隐藏字段,否则我们将保留默认值 "Save"。

第三,转到您的控制器,并从 POST 数组中读取此字段:

if (isset($_POST["my_button_name"]) && $_POST["my_button_name"] == 'save_and_close' )
{
    // save and close clicked
}
else
{
    // save clicked
}   

应该就这些了。如果您找到 "more proper" 的方法,请告诉我。

打开\assets\grocery_crud\themes\datatables\edit.php

然后粘贴之前:

<div class='form-content form-div'>
    <?php echo form_open( $update_url, 'method="post" id="crudForm" enctype="multipart/form-data"'); ?>"

粘贴这个

<?php switch ($this->basic_db_table) {
                case "table1":
                    ?><button type="button" class="btn btn-default" aria-label="Left Align">
                        button text 1
                    </button><?php
                    break;
                case "table2":
                    ?><button type="button" class="btn btn-default" aria-label="Left Align">
                        text table2
                    </button><?php
                    ?><button type="button" class="btn btn-default" aria-label="Left Align">
                        text table 3 showed
                    </button><?php
                    break;
                default:
                    echo "No buttons";
            }
        ?>