CodeIgniter Forums
There is no data to insert. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: There is no data to insert. (/showthread.php?tid=78738)



There is no data to insert. - matamune - 03-04-2021

my app/controllers -> Setting.php
Code:
<?php

namespace App\Controllers;

use CodeIgniter\HTTP\Response;
use CodeIgniter\HTTP\ResponseInterface;
use Exception;
use ReflectionException;

class Setting extends BaseController
{
  public function __construct() {
    $this->settingModel         = model('App\Models\SettingModel');
  }

  // create
  public function create() {
    try {
      $this->checkRole($this->request, ['admin', 'moderator']);

      $info = $this->getRequestInput($this->request);
      var_dump($info);
      $id = $this->settingModel->insert($info);

      return $this->getResponse(
        [
          'id' => $id
        ],
        201
      );
    } catch (Exception $e) {
      return $this->getResponse(
        [
          'messages' => $e->getMessage()
        ],
        400
      );
    }
  }
}

my app/models/ -> SettingModel.php
PHP Code:
<?php

namespace App\Models;

use 
CodeIgniter\Model;

class 
SettingModel extends Model
{
  protected $table          'setting';
  protected $primaryKey     'id';
  protected $allowedFields  = ['name, value'];
  protected $useTimestamps  true;
  protected $createdField   'created_at';
  protected $updatedField   'updated_at';


What was wrong with my code ?? Someone can help ?