BadMethodCallException Call to undefined method App\Models\UserModel::escapeString - KhongGuan - 04-19-2021
This error after clicking 'Biodata' menu. I don't know if the issue lies with the if Call to undefined method App\Models\UserModel::escapeString. This error appears when im typing code $id = $userModel->escapeString(esc($this->request->uri->getSegment(4)));
My Controller
Code: public function change_profile()
{
helper(['form', 'url']);
$userModel = new UserModel();
$id = $userModel->escapeString(esc($this->request->uri->getSegment(4)));
if ($this->request->getMethod() == 'post') {
$rules = [
'nama' => 'required|alpha_space|min_length[2]',
];
if ($this->validate($rules)) {
$params = [
'nama' => $userModel->escapeString(esc($this->request->getPost('nama'))),
];
$update = $userModel->update($id, $params);
if ($update) {
session()->setFlashdata('success', 'Berhasil edit data');
return redirect()->route('admin/user/change_profile');
} else {
session()->setFlashdata('danger', 'Gagal edit data');
return redirect()->route('admin/user/change_profile')->withInput();
}
} else {
$data['validation'] = $this->validator;
}
}
$data['title'] = 'Dokumen';
$data['user'] = $userModel->find($id);
return view('admin/users/profile', $data);
}
My View
Code: <div class="container">
<div class="card">
<div class="card-body">
<form action="<?= base_url('admin/user/change_profile') ?>" method="POST" enctype="multipart/form-data">
<?= csrf_field(); ?>
<div class="form-group">
<label for="nama">Nama</label>
<input type="text" class="form-control" name="nama" id="nama" value="<?= $user['nama'] ?>" >
</div>
<input type="submit" value="Update" class="btn btn-info"/>
</form>
</div>
</div>
</div>
im using Codeigniter 4. Whats wrong with my code
RE: BadMethodCallException Call to undefined method App\Models\UserModel::escapeString - InsiteFX - 04-19-2021
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.
RE: BadMethodCallException Call to undefined method App\Models\UserModel::escapeString - KhongGuan - 04-19-2021
(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();
}
}
RE: BadMethodCallException Call to undefined method App\Models\UserModel::escapeString - InsiteFX - 04-20-2021
Also looking at your model there is no escapeString method it it either that's why your getting an error.
|