表是使用 render_datatable 使用 MySQL 数据库中的动态数据创建的,但控制器或模型中没有用于获取数据的方法

问题描述 投票:0回答:1

在render_datatable函数中,当我将第二个参数从“leads”更改为“lead”时,即使有数据,表格也显示为空白。我不明白从数据库中获取数据的位置。 控制器或模型中没有用于获取数据的方法,并且这里也没有使用 AJAX 来获取数据。 还有其他方法从 MySQL 数据库获取数据吗?

````<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>
<?php init_head(); ?>
<div id="wrapper">
   <div class="content">
      <div class="row">
         <div class="col-md-12">
            <div class="panel_s">
               <div class="panel-body">
                  <?php
                     $table_data = array();
                     $_table_data = array(
                        '<span class="hide"> - </span><div class="checkbox mass_select_all_wrap"><input type="checkbox" id="mass_select_all" data-to-table="leads"><label></label></div>',
                        array(
                        'name'=>_l('the_number_sign'),
                        'th_attrs'=>array('class'=>'toggleable', 'id'=>'th-number')
                        ),
                        array(
                        'name'=>_l('leads_dt_name'),
                        'th_attrs'=>array('class'=>'toggleable', 'id'=>'th-name')
                        ),
                     );
                     if(is_gdpr() && get_option('gdpr_enable_consent_for_leads') == '1') {
                        $_table_data[] = array(
                           'name'=>_l('gdpr_consent') .' ('._l('gdpr_short').')',
                           'th_attrs'=>array('id'=>'th-consent', 'class'=>'not-export')
                        );
                     }
                     $_table_data[] = array(
                        'name'=>_l('lead_company'),
                        'th_attrs'=>array('class'=>'toggleable', 'id'=>'th-company')
                     );
                     $_table_data[] =   array(
                        'name'=>_l('leads_dt_email'),
                        'th_attrs'=>array('class'=>'toggleable', 'id'=>'th-email')
                     );
                     $_table_data[] =  array(
                        'name'=>_l('leads_dt_phonenumber'),
                        'th_attrs'=>array('class'=>'toggleable', 'id'=>'th-phone')
                     );
                     $_table_data[] =  array(
                        'name'=>_l('leads_dt_lead_value'),
                        'th_attrs'=>array('class'=>'toggleable', 'id'=>'th-lead-value')
                        );
                     $_table_data[] =  array(
                        'name'=>_l('tags'),
                        'th_attrs'=>array('class'=>'toggleable', 'id'=>'th-tags')
                     );
                     $_table_data[] = array(
                        'name'=>_l('leads_dt_assigned'),
                        'th_attrs'=>array('class'=>'toggleable', 'id'=>'th-assigned')
                     );
                     $_table_data[] = array(
                        'name'=>_l('leads_dt_status'),
                        'th_attrs'=>array('class'=>'toggleable', 'id'=>'th-status')
                     );
                     $_table_data[] = array(
                        'name'=>_l('leads_source'),
                        'th_attrs'=>array('class'=>'toggleable', 'id'=>'th-source')
                     );
                     $_table_data[] = array(
                        'name'=>_l('leads_dt_last_contact'),
                        'th_attrs'=>array('class'=>'toggleable', 'id'=>'th-last-contact')
                     );
                     $_table_data[] = array(
                        'name'=>_l('leads_dt_datecreated'),
                        'th_attrs'=>array('class'=>'date-created toggleable','id'=>'th-date-created')
                     );
                     foreach($_table_data as $_t){
                        array_push($table_data,$_t);
                     }
                     $custom_fields = get_custom_fields('leads',array('show_on_table'=>1));
                     foreach($custom_fields as $field){
                     array_push($table_data,$field['name']);
                     }
                     $table_data = hooks()->apply_filters('leads_table_columns', $table_data);
                     render_datatable($table_data,'leads',
                     array('customizable-table'),
                     array(
                        'id'=>'table-leads',
                        'data-last-order-identifier'=>'leads',
                        'data-default-order'=>get_table_last_order('leads'),
                        )); ?>
                     </div>
                  </div>
               </div>
            </div>
         </div>
      </div>
   </div>
</div>
<?php init_tail(); ?>
</body>
</html>

当我尝试向同一个表中添加两列(这些列已存在于“潜在客户”表中)时,该表再次变为空白。似乎 render_datatable 函数“leads”的第二个参数已经定义了有限数量的列。 这是用于创建表的 render_datatable 函数。

function render_datatable($headings = [], $class = '', $additional_classes = [''], $table_attributes = [])
{
    $_additional_classes = '';
    $_table_attributes   = ' ';
    if (count($additional_classes) > 0) {
        $_additional_classes = ' ' . implode(' ', $additional_classes);
    }
    $CI      = & get_instance();
    $browser = $CI->agent->browser();
    $IEfix   = '';
    if ($browser == 'Internet Explorer') {
        $IEfix = 'ie-dt-fix';
    }

    foreach ($table_attributes as $key => $val) {
        $_table_attributes .= $key . '=' . '"' . $val . '" ';
    }

    $table = '<div class="' . $IEfix . '"><table' . $_table_attributes . 'class="dt-table-loading table table-' . $class . '' . $_additional_classes . '">';
    $table .= '<thead>';
    $table .= '<tr>';
    foreach ($headings as $heading) {
        if (!is_array($heading)) {
            $table .= '<th>' . $heading . '</th>';
        } else {
            $th_attrs = '';
            if (isset($heading['th_attrs'])) {
                foreach ($heading['th_attrs'] as $key => $val) {
                    $th_attrs .= $key . '=' . '"' . $val . '" ';
                }
            }
            $th_attrs = ($th_attrs != '' ? ' ' . $th_attrs : $th_attrs);
            $table .= '<th' . $th_attrs . '>' . $heading['name'] . '</th>';
        }
    }
    $table .= '</tr>';
    $table .= '</thead>';
    $table .= '<tbody></tbody>';
    $table .= '</table></div>';
    echo $table;
}```
codeigniter datatables controller
1个回答
0
投票
render_datatable($table_data,'leads',
  array('customizable-table'),
  array(
    'id'=>'table-leads',
    'data-last-order-identifier'=>'leads',
    'data-default-order'=>get_table_last_order('leads'),
));

您是否还更改了引用

'leads'
的数组元素?

如果仅更改

render_datatable
的第二个参数,则
$additional_classes
$table_attributes
可能无法正确匹配。

© www.soinside.com 2019 - 2024. All rights reserved.