I have a problem when I want to change the data level, the problem is that the data level does not match the user ID
public function updateLevel($level)
{
$checkuserToken = $this->users->where('level', $level)->first();
if (count($checkuserToken) > 1) {
if ($level == 'admin') {
$data = [
'level' => 'superadmin',
];
$activateUser = $this->users->update($checkuserToken, $data);
if ($activateUser) {
return redirect()->to('/admin/admin');
} else {
return redirect()->to('/admin/admin');
}
# code...
} else {
# code...
$data = [
'level' => 'admin',
];
$activateUser = $this->users->update($checkuserToken, $data);
if ($activateUser) {
return redirect()->to('/admin/admin');
} else {
return redirect()->to('/admin/admin');
}
# code...
}
} else {
return redirect()->to('/admin/admin');
}
this is my controller
<?= $this->extend('admin/template') ?>
<?= $this->section('content') ?>
<main class="col-md-9 ml-sm-auto col-lg-10 px-md-4 py-4">
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="/admin/admin">Admin</a></li>
<li class="breadcrumb-item active" aria-current="page">Overview</li>
</ol>
</nav>
<h1 class="h2">Admin</h1>
<a href="<?= base_url('admin/addAdmin') ?>"><button type="button" class="btn btn-dark mt-3 mb-2">Add Data</button></a>
<br>
<table class="table table-bordered">
<thead>
<tr>
<th>No</th>
<th>Nama</th>
<th>Username</th>
<th>Email</th>
<th>Gambar</th>
<th>Level</th>
<th>delete</th>
</tr>
</thead>
<tbody>
<?php $no = 1; ?>
<?php foreach ($admin as $r) : ?>
<tr>
<td><?php echo $no++ ?></td>
<td><?php echo $r['nama'] ?></td>
<td><?php echo $r['username'] ?></td>
<td><?php echo $r['email'] ?></td>
<td><img src="<?= base_url('asset/upload/image/' . $r['image']) ?>" alt="" width="90" height="90" class="img-thumbnail"></td>
<td><a href="<?= base_url('/admin/level/' . $r['level']) ?>"><?php echo $r['level'] ?></a></td>
<td><a href=""><button type="button" class="btn btn-danger">Hapus</button></a></td>
</tr>
<?php endforeach ?>
</tbody>
</table>
<footer class="pt-5 d-flex justify-content-between">
<span>Copyright © 2019-2020 <a href="https://themesberg.com">Themesberg</a></span>
<ul class="nav m-0">
<li class="nav-item">
<a class="nav-link text-secondary" aria-current="page" href="#">Privacy Policy</a>
</li>
<li class="nav-item">
<a class="nav-link text-secondary" href="#">Terms and conditions</a>
</li>
<li class="nav-item">
<a class="nav-link text-secondary" href="#">Contact</a>
</li>
</ul>
</footer>
</main>
<?= $this->endSection() ?>
this is my views
<?php
namespace AppModels;
use CodeIgniterModel;
class AdminModel extends Model
{
protected $table = 'admin';
protected $primaryKey = 'id';
protected $useAutoIncrement = true;
protected $returnType = 'array';
protected $useSoftDeletes = false;
protected $protectFields = true;
protected $allowedFields = ['nama', 'username', 'email', 'password', 'image', 'level', 'created_at'];
protected bool $allowEmptyInserts = false;
protected bool $updateOnlyChanged = true;
protected array $casts = [];
protected array $castHandlers = [];
// Dates
protected $useTimestamps = false;
protected $dateFormat = 'datetime';
// Validation
protected $validationRules = [
'nama' => 'required',
'username' => 'required|max_length[254]|is_unique[admin.username,id,{id}]',
'email' => 'required|max_length[254]|valid_email',
'password' => 'required|max_length[255]|min_length[8]',
'image' => 'uploaded[image]|mime_in[image,image/jpg,image/jpeg,image/gif,image/png]|max_size[image,2048]'
];
protected $validationMessages = [];
protected $skipValidation = false;
protected $cleanValidationRules = true;
}
this is my model
example
I want to change the data level with the user name tamaulanaa_
but that changes the data level with the user name udintod
what I expect is that if I change the data level it changes according to the user ID or username
what I expect is that if I change the data level it changes according to the user ID or username
triahmad maulana is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.