Welcome Guest, Not a member yet? Register   Sign In
Why unknow column 'slug_safelink' ?
#3

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


Messages In This Thread
Why unknow column 'slug_safelink' ? - by flux1on - 11-04-2020, 07:06 AM
RE: Why unknow column 'slug_safelink' ? - by flux1on - 11-04-2020, 11:25 PM



Theme © iAndrew 2016 - Forum software by © MyBB