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 ?