【问题标题】:datatables serverside join in codeigniter数据表服务器端加入codeigniter
【发布时间】:2017-08-15 04:12:53
【问题描述】:

我尝试通过 ajax 在 codeigniter 中使用数据表服务器端合并数据,但我得到错误结果,像这样

消息:在布尔值上调用成员函数 result()

文件名:models/model_masterdata_menu.php

行号: 66

private function _get_datatables_query()
            { //term is value of $_REQUEST['search']['value']
                $column_search = array('m.menu_id, m.menu_nama, m.menu_url, sm.statusmenu_nama');
                $column_order = array('m.menu_id, m.menu_nama, m.menu_url, sm.statusmenu_nama',NULL);
                $order = array('m.menu_id' => 'desc');
                $this->db->select('m.menu_id, m.menu_nama, m.mmenu_url, sm.statusmenu_nama');
                $this->db->from('menu as m');
                $this->db->join('status_menu sm', 'sm.statusmenu_id = m.statusmenu_id','left');
                $i = 0;

                foreach ($column_search as $item) // loop column
                {
                    if($_POST['search']['value']) // if datatable send POST for search
                    {

                        if($i===0) // first loop
                        {
                                $this->db->group_start(); // open bracket. query Where with OR clause better with bracket. because maybe can combine with other WHERE with AND.
                                $this->db->like($item, $_POST['search']['value']);
                        }
                        else
                        {
                                $this->db->or_like($item, $_POST['search']['value']);
                        }

                        if(count($column_search) - 1 == $i) //last loop
                            $this->db->group_end(); //close bracke
                 }

                 $i++;
             }
                if(isset($_POST['order'])) // here order processing
                {
                     $this->db->order_by($order[$_POST['order']['0']['column']], $_POST['order']['0']['dir']);
                }
                else if(isset($this->order))
                {
                     /*$order = $this->order;*/
                     $this->db->order_by(key($order), $order[key($order)]);
                }

            }


            function get_datatables()
            {

              $this->_get_datatables_query();
                /*$this->_get_datatables_query();*/
              if($_POST['length'] != -1)
              $this->db->limit($_POST['length'], $_POST['start']);

                $result = $query->result(); # added

            }

怎么了? 谁能帮帮我?

【问题讨论】:

  • 这是foreach ($column_search as $item)第32行吗?
  • @Jigar Shah,对不起,我稍后检查后收到错误调用数组上的成员函数 result()
  • 只是一个顶部你的类和文件名应该只有第一个字母大写Filename: models/Model_masterdata_menu.php 而不是Filename: models/model_masterdata_menu.php 这里解释codeigniter.com/user_guide/general/styleguide.html#file-naming
  • @wolfgang1983,同样的错误没有变化
  • 只是一个小费@muzamilindra

标签: php ajax codeigniter datatable


【解决方案1】:

我不知道为什么它告诉你Call to a member function result() on boolean,因为根据你的代码你甚至没有正确声明$query

你有没有尝试过类似的方法?

function get_datatables()
{

    $this->_get_datatables_query();
    if($_POST['length'] != -1)  $this->db->limit($_POST['length'], $_POST['start']);
    $query = $this->db->get();

    return ($query->num_rows() > 0) ?   $query->result()    :   false;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-21
    • 2016-06-11
    • 2018-06-16
    • 1970-01-01
    • 2022-01-16
    • 1970-01-01
    • 1970-01-01
    • 2016-04-23
    相关资源
    最近更新 更多