Error Call to undefined method App\Models\UserModel::escapeString

Mohon bantuannya kakak-kakak.

Jdi saya mau update data profile, tapi ketika saya mengakses menu update profile muncul pesan  Error Call to undefined method App\Models\UserModel::escapeString, errornya muncul ketika saya tambahakan kode berikut :

$id = $userModel->escapeString(esc($this->request->uri->getSegment(4)));

Controller :

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);
	}

View :

<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>

Screenshot_1.png

Mohon bantunnya, kesalahan dari kode saya dibagian mananya ya? Terimakasih

avatar bagusti
@bagusti

6 Kontribusi 0 Poin

Diperbarui 3 tahun yang lalu

2 Jawaban:

<div>arti errornya metode escapeString tidak tersedia untuk model tersebut.<br>cek lagi penggunannya di sini<br><a href="https://www.codeigniter.com/user_guide/database/queries.html">https://www.codeigniter.com/user_guide/database/queries.html</a></div>

avatar hilmanski
@hilmanski

2686 Kontribusi 2135 Poin

Dipost 3 tahun yang lalu

Tanggapan

kalo muncul pesan ini Trying to access array offset on value of type null itu yang salah apa ya kak?

<div>kalo muncul pesan ini Trying to access array offset on value of type null itu yang salah apa ya kak?<br><figure data-trix-attachment="{&quot;contentType&quot;:&quot;image/png&quot;,&quot;filename&quot;:&quot;image.png&quot;,&quot;filesize&quot;:49721,&quot;height&quot;:522,&quot;url&quot;:&quot;https://i.ibb.co/vdGMdxz/image.png&quot;,&quot;width&quot;:1244}" data-trix-content-type="image/png" data-trix-attributes="{&quot;presentation&quot;:&quot;gallery&quot;}" class="attachment attachment--preview attachment--png"><img src="https://i.ibb.co/vdGMdxz/image.png" width="1244" height="522"><figcaption class="attachment__caption"><span class="attachment__name">image.png</span></figcaption></figure></div>

avatar bagusti
@bagusti

6 Kontribusi 0 Poin

Dipost 3 tahun yang lalu

Login untuk ikut Jawaban