我想问一下在杂货杂货中可以自动计算的功能。
例如:我有一些列a、b和total_a_b,我使用了callback_column函数,但它现在工作得很好,callback_column只是在视图页面上显示结果,不能自动保存到数据库中。可以引用它的功能是什么?是否有一种方法能以字段的形式显示自动计算?
这是我的密码:
public function try() {
$crud = new grocery_CRUD();
$crud->set_table('try');
$crud->columns('a', 'b', 'total');
$crud->callback_column('total', array($this, '_callback_column_total'));
$output = $crud->render();
$this->_example_output($output);
}
public function _callback_column_total ($value, $row) {
$a = $row->a;
$b = $row->b;
$total=$a + $b;
return $total;
}发布于 2016-09-17 15:20:04
- First you need to make sure that, the this field is column in your table, then tell GroceryCrud that this field is available, but invisible in form. $crud->change_field_type('your_field',‘不可见’);
- Second (optional), you can use 2 callbacks: calback\_before\_update, calback\_before\_insert to validate or use PHP to handle the value of this field
API文档可以帮助:functions
您可以使用javascript添加新元素并处理自动计算。请记住,应该有一个隐藏的输入,将与您的帖子请求张贴到食品杂货的控制器。您需要确保var_dump的post请求( $post_data在回调中的值: callback_before_insert或call_back_before_update )会附带这个值。
https://stackoverflow.com/questions/39521370
复制相似问题