Welcome Guest, Not a member yet? Register   Sign In
ResourceController and model->update, is this a bug
#1

(This post was last modified: 10-05-2021, 08:46 AM by rich8374.)

Hi, I'm getting errors when trying to do a database update in a ResourceController, some ways work and some ways throw errors. Is this a bug?
Using CodeIgniter 4.1.4, here is a simplified example, I've commented out the lines which throw errors.
PHP Code:
namespace App\Controllers;

use 
CodeIgniter\RESTful\ResourceController;

class 
Feedback extends ResourceController
{
    protected $modelName 'App\Models\FeedbackModel';
    protected $format    'json';

    public function index()
    {
        $db = \Config\Database::connect();
        // works
        $db->table('feedback')->update(['score' => '20'], "id = 1");
        // works
        $db->table('feedback')->update(['score' => '21'], ['id' => 1]);
        // TypeError, Return value of CodeIgniter\\BaseModel::transformDataToArray() must be of the type array, string returned
        //$this->model->update(['score' => '22'], "id = 1");
        // DataException, There is no data to update
        //$this->model->update(['score' => '23'], ['id' => 1]);
        // Works
        $this->model->set('score''24');
        $this->model->where('id'1);
        $this->model->update();
    }

Does anyone know why model->update() throws those errors?
Thanks.
Reply
#2

BaseBuilder::update() !== BaseModel::update()
Reply
#3

see

PHP Code:
use CodeIgniter\RESTful\ResourceController;

class 
Feedback extends ResourceController
{
    protected $modelName 'App\Models\FeedbackModel';
    protected $format    'json';

    public function index()
    {
    
$model 
= new Model();
        $model->update($id,['some'=>'thing']);
    }

Enlightenment  Is  Freedom
Reply




Theme © iAndrew 2016 - Forum software by © MyBB