嗨,我正在使用带有HMVC的Grocery,而且我面临着一些奇怪的问题。
class Source extends MX_Controller
{
function __construct() {
parent::__construct();
}
function index(){
try{
$crud = new grocery_CRUD();
$crud->set_theme('datatables');
$crud->set_table('source');
$crud->set_subject('Source');
$output = $crud->render();
$data['css_files'] = $output->css_files;
$data['js_files'] = $output->js_files;
$data['output'] = $output->output;
$this->template->title('Source')
->set_layout('default')
->build('example', $data );
}catch(Exception $e){
show_error($e->getMessage().' --- '.$e->getTraceAsString());
}
}
}
在源表中,我只有一个列"name“,另一个列是id,带有自动增量和主键。
当我添加或插入数据时,它会在表中添加多个数据,有时是重复数据的3倍或4倍。
我也在使用模板库。
这是我第一次用这个Grocery面对的奇怪问题,有人能帮我解决这个问题吗?
发布于 2015-09-18 22:13:07
我在多次插入杂货数据时也有同样的问题,我通过在js文件中添加下面的代码来解决这个问题。
我使用的是datatable主题,文件是grocery_crud\themes\datatables\js\datatables-add.js
$('#save-and-go-back-button').click(function(event){
event.stopImmediatePropagation();
save_and_close = true;
$('#crudForm').trigger('submit');
});
$('#crudForm').submit(function(event){
event.stopImmediatePropagation();
$(this).ajaxSubmit({
url: validation_url,
.......
我们需要在单击和提交事件之后添加"event.stopImmediatePropagation();“。
这将有助于停止多重钝插入。
发布于 2015-08-26 23:37:45
主计长,尝试这样做:
class Source extends MX_Controller
{
function __construct() {
parent::__construct();
}
function index(){
try{
$crud = new grocery_CRUD();
$crud->set_theme('datatables');
$crud->set_table('source');
$crud->set_subject('Source');
//edit the id of source table as it's on your table..
$crud->set_primary_key('id', 'source');
//set the columns you want
$crud->columns(
'id',
'name'
);
//how do you want to display them in the frontend
$crud->display_as('id', 'id');
$crud->display_as('name', 'name');
$table = $crud->render();
$this->_table_output($table);
}catch(Exception $e){
show_error($e->getMessage().' --- '.$e->getTraceAsString());
}
}
}
所需的额外职能:
private function _table_output($output = null)
{
//load reservations table
$this->load->view('yourviewfile', $output);
}
查看:
<?php
foreach($output['css_files'] as $file): ?>
<link type="text/css" rel="stylesheet" href="<?php echo $file; ?>" />
<?php endforeach; ?>
<?php foreach($output['js_files'] as $file): ?>
<script src="<?php echo $file; ?>"></script>
<?php endforeach; ?>
<div>
<?php echo $output['output']; ?>
</div>
发布于 2016-11-04 15:50:54
在显示杂货crud时,有理由列出重复行:-如果在视图和表之间有一个关系函数(),那么必须确保该视图有唯一的 ID列(没有重复值的),否则您将得到重复的行,解决方案是使用:$crud--set_primary_key(‘id’,'viewname');将该行放在关系函数之前。
https://stackoverflow.com/questions/32242834
复制相似问题