(11-04-2020, 10:45 AM)mlurie Wrote: Did you initialize the $allowedFields array in your Model?
PHP Code:
protected $allowedFields = ['nama_safelink', 'slug_safelink', 'url_safelink', 'hits_safelink'];
Also, you don't really need the saveData, updateDate, and deleteData methods if you are using CodeIgniter 4's model. CodeIgniter already has insert, update, delete, and save methods available to you: https://codeigniter.com/user_guide/models/model.html.
i already add $allowedfields to all models, sry no update in thread
Code:
<?php namespace App\Models;
use CodeIgniter\Model;
class Safelink_model extends Model
{
protected $table = 'safelink';
protected $primaryKey = 'kode_safelink';
protected $allowedFields = ['kode_safelink', 'nama_safelink', 'slug_safelink', 'url_safelink', 'hits_safelink', 'created_safelink'];
public function goLink($slug)
{
$query = $this->db->table($this->table)
->where('slug_safelink', $slug)
->get();
return $query->getRow();
}
public function getData($id = null)
{
if($id === null){
return $this->findAll();
} else {
return $this->getWhere(['kode_safelink' => $id]);
}
}
public function saveData($data)
{
$query = $this->db->table($this->table)->insert($data);
return $query;
}
public function updateData($data, $id)
{
$query = $this->db->table($this->table)->update($data, array('kode_safelink' => $id));
return $query;
}
public function CounterSafelink($data, $id)
{
$query = $this->db->table($this->table)->update(array('hits_safelink' => $data+1), array('slug_safelink' => $id));
return $query;
}
public function deleteData($id)
{
$query = $this->db->table($this->table)->delete(array('kode_safelink' => $id));
return $query;
}
}
i create function saveData,updateData,deleteData for calling function models in controller