我的代码点火器更新功能不工作



我有简单的代码来更新数据,但不幸的是,它根本不起作用。只显示空白页,不显示任何错误消息。对我的索引和视图编辑的查询运行良好。但不是为了更新请帮助我。

这是我的模型:ModelSiswa.php

<?php
namespace AppModels;
use CodeIgniterModel;
class ModelSiswa extends Model
{
protected $table = 'users';
protected $primaryKey = 'id_user';
protected $allowedFields = ['nama_user', 'alamat', 'tgl', 'hp', 'email'];
protected $useTimestamps = true;
protected $createdField  = 'created_at';
protected $updatedField  = 'updated_at';
protected $deletedField  = 'deleted_at';
protected $returnType = 'array';
public function __construct()
{
parent::__construct();
}
}

这是我的控制器:Siswa.php

<?php
namespace AppControllers;
use AppControllersBaseController;
use AppModelsModelSiswa;
class Siswa extends BaseController
{
public function index()
{
$model = new ModelSiswa();
$data['siswa'] = $model->findAll();
return view('viewSiswa', $data);
}
public function editSiswa($id = null)
{
$model = new ModelSiswa();
$data['siswa'] = $model->where('id_user', $id)->first();
return view('siswa_edit_view', $data);
}
public function updat()
{
$model = new ModelSiswa();
$id = $this->request->getVar('id', FILTER_SANITIZE_NUMBER_INT);
$data = [
'nama_user' => $this->request->getVar('nama_user'),
'alamat'  => $this->request->getVar('alamat'),
'tgl'  => $this->request->getVar('tgl'),
'hp'  => $this->request->getVar('hp'),
'email'  => $this->request->getVar('email')
];
if ($this->model->update($id, $data)) {
return $this->response->redirect(base_url('siswa'));
} else {
return $this->response->redirect(base_url('siswa/editsiswa/' . $id));
}
}

这是我的索引视图:viewSiswa.php

<?php if (count($siswa) > 0) : ?>
<table class='table'>
<tr>
<th>Id</th>
<th>Nama</th>
<th>Alamat</th>
<th>No HP</th>
<th>Tgl Lahir</th>
<th>Email</th>
<th>Created</th>
<th>Action</th>
</tr>
<?php foreach ($siswa as $emp) : ?>
<tr>
<td><?= $emp['id_user']; ?></td>
<td><?= $emp['nama_user']; ?></td>
<td><?= $emp['alamat']; ?></td>
<td><?= $emp['hp']; ?></td>
<td><?= $emp['tgl']; ?></td>
<td><?= $emp['email']; ?></td>
<td><?= $emp['created_at']; ?></td>
<td>
<a href='<?= base_url(); ?>/siswa/editsiswa/<?= $emp['id_user'] ?>'>Edit</a>
<a href='<?= base_url(); ?>/siswa/delete/<?= $emp['id_user'] ?>'>Delete</a>
</td>
</tr>
<?php endforeach; ?>
</table>
<?php endif; ?>

这是我的视图更新siswa_edit_View.php

<form method="post" action="<?= base_url() . '/siswa/updat'; ?>">
<div class="modal-header">
<h4 class="modal-title">Edit Siswa</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label>Nama</label>
<input type="text" name="nama_user" id="edit_nama" class="form-control" value="<?= $siswa['nama_user']; ?>" required>
</div>
<div class="form-group">
<label>Alamat</label>
<input type="text" name="alamat" id="edit_alamat" class="form-control" value="<?= $siswa['alamat']; ?>" required>
</div>
<div class="form-group">
<label>No HP</label>
<input type="number" name="hp" id="edit_hp" class="form-control" value="<?= $siswa['hp']; ?>" required>
</div>
<div class="form-group">
<label>Tgl Lahir</label>
<input type="text" name="tgl" id="edit_tgl" class="form-control" value="<?= $siswa['tgl']; ?>" required>
</div>
<div class="form-group">
<label>Email</label>
<input type="text" name="email" id="edit_email" class="form-control" value="<?= $siswa['email']; ?>" required>
<input type="hidden" name="id" id="edit_id" value="<?= $siswa['id_user']; ?>" required>
</div>
</div>
<div class="modal-footer">
<a class="btn btn-dark rounded-0 col-2" href="<?= base_url("/siswa") ?>"><i class="fa fa-angle-left"></i> Back to List</a>
<input type="submit" class="btn btn-info" value="Update">
</div>
</form>

已解决。我忘记处理我的地址过滤器了。

相关内容

  • 没有找到相关文章

最新更新