Welcome Guest, Not a member yet? Register   Sign In
BadMethodCallException Call to undefined method App\Models\UserModel::escapeString
#3

(04-19-2021, 08:56 PM)InsiteFX Wrote: The Model has no escapeString unless you created a method for it in which case you did
not show the escapeString method.

So without seeing the method we can not help you.

This is my model

Code:
<?php

namespace App\Models;

use CodeIgniter\Model;
use CodeIgniter\HTTP\RequestInterface;
use Config\Services;

class UserModel extends Model
{
    protected $table      = 'users';
    protected $primaryKey = 'id_user';
    protected $allowedFields = ['nama', 'email', 'password', 'id_level', 'tempat_lahir', 'nip', 'alamat', 'telp', 'avatar1', 'avatar2','avatar3','avatar4','avatar5','avatar6', 'avatar7', 'avatar8', 'avatar9', 'avatar10', 'avatar11', 'avatar12', 'avatar13', 'avatar14', 'avatar15', 'avatar16', 'avatar17', 'avatar18', 'avatar19', 'jk', 'lulusan', 'tanggal_lahir', 'jurusan', 'prodi', 'pt', 'pengalaman', 'pangkat'];
    protected $useTimestamps = true;


    // datatables config
    protected $column_order = array(0, 1, 2, 3, 4, 5);
    protected $column_search = array('nama', 'email');
    protected $order = array('created_at' => 'desc');
    protected $request;

    function __construct(RequestInterface $request = null)
    {
        parent::__construct();
        $this->request = $request;
    }

    public function _get_datatables_query()
    {
        $request = Services::request();
        $i = 0;
        foreach ($this->column_search as $item) {
            if ($request->getPost('search')['value']) {
                if ($i === 0) {
                    $this->groupStart();
                    $this->like($item, $request->getPost('search')['value']);
                } else {
                    $this->orLike($item, $request->getPost('search')['value']);
                }
                if (count($this->column_search) - 1 == $i)
                    $this->groupEnd();
            }
            $i++;
        }

        if ($request->getPost('order')) {
            $this->orderBy($this->column_order[$request->getPost('order')['0']['column']], $request->getPost('order')['0']['dir']);
        } else if (isset($this->order)) {
            $order = $this->order;
            $this->orderBy(key($order), $order[key($order)]);
        }
    }

    public function get_datatables()
    {
        $request = Services::request();
        $this->_get_datatables_query();
        if ($request->getPost('length') != -1)
            $this->limit($request->getPost('length'), $request->getPost('start'));
        $query = $this->get();
        return $query->getResult();
    }

    public function count_filtered()
    {
        $this->_get_datatables_query();
        return $this->countAllResults();
    }

    public function count_all()
    {
        $tbl_storage = $this->db->table($this->table);
        return $tbl_storage->countAllResults();
    }

}
Reply


Messages In This Thread
RE: BadMethodCallException Call to undefined method App\Models\UserModel::escapeString - by KhongGuan - 04-19-2021, 09:43 PM



Theme © iAndrew 2016 - Forum software by © MyBB