CodeIgniter Forums
Model - no data to update - 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: Model - no data to update (/showthread.php?tid=74012)



Model - no data to update - Nome - 07-08-2019

My model :
PHP Code:
public function updateTest($id$stat$title) {
 
   $this->asArray()->where(['id' => 2])->protect(false)->update([
 
     'stat' => $stat,
 
     'title'=> $title]);
 } 

returned :


Quote:CodeIgniter\Database\Exceptions\DataException

There is no data to update.
In POST i look all key and value.

Tell me what could be a mistake? Thank you!


RE: Model - no data to update - InsiteFX - 07-08-2019

Are you using CodeIgniter 4 Model or Query Builder?

Not sure where you are getting this-> from


RE: Model - no data to update - Nome - 07-08-2019

(07-08-2019, 08:16 AM)InsiteFX Wrote: Are you using CodeIgniter 4 Model or Query Builder?

Not sure where you are getting this-> from

Before i have:


PHP Code:
 protected $table        'test';
 
 protected $primaryKey   'id'



RE: Model - no data to update - InsiteFX - 07-09-2019

If your using CodeIgniter's Model then you need to extend it into your own Model Class.


RE: Model - no data to update - Nome - 07-09-2019

(07-09-2019, 02:42 AM)InsiteFX Wrote: If your using CodeIgniter's Model then you need to extend it into your own Model Class.

What do you mean? Example? 

I have my namespace and use CI Model.  

PHP Code:
namespace Modules\Test\Models;
use 
CodeIgniter\Model
After seeing what parameters the update() function accepts, I realized that instead of "->where()->" you can use the parameter inside the "update($where, ['key' => $param ])" function. Only in vain created a topic ((

But the truth is, I did not quite understand how to work with the replacement then, since this "replace()" function accepts only an array of data.


RE: Model - no data to update - InsiteFX - 07-10-2019

TestModel:

PHP Code:
<?php namespace Modules\Test\Models;

/**
 * -----------------------------------------------------------------------
 * Class        TestModel
 *
 * @project     ci4admin
 * @author      Raymond L King Sr.
 * @link        https://www.procoversfx.com
 * @copyright   Copyright (c) 2009 - 2019 Custom Software Designers, LLC.
 * @license     https://www.procoversfx.com/license
 * -----------------------------------------------------------------------
 */

use CodeIgniter\Model;

class 
TestModel extends Model
{
 
   /**
     * Class properties go here.
     * -------------------------------------------------------------------
     * public, private, protected, static and const.
     */


 
   /**
     * Name of database table
     *
     * @var string
     */
 
   protected $table 'tableName';

 
   // -------------------------------------------------------------------

 
   /**
     * __construct ()
     * -----------------------------------------------------------------------
     *
     * Class    Constructor
     *
     * NOTE: Not needed if not setting values or extending a Class.
     *
     */
 
   public function __construct()
 
   {
 
       parent::__construct();
 
   }

 
   // -----------------------------------------------------------------------

  // End of TestModel Model Class.

/**
 * -----------------------------------------------------------------------
 * Filename: TestModel.php
 * Location: ./Modules/Test/Models/TestModel.php
 * -----------------------------------------------------------------------
 */ 

A test model for setting up a model in modules.

I have code templates made up in my phpStorm for everything, like above model.

You can setup the other variables from CodeIgniter's model in your new model.

I try to use Entity Classes for my models, Entity Class is a good read in the User Guide.