• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Model - no data to update

#1
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!
Reply

#2
Are you using CodeIgniter 4 Model or Query Builder?

Not sure where you are getting this-> from
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#3
(07-08-2019, 09: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'
Reply

#4
If your using CodeIgniter's Model then you need to extend it into your own Model Class.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#5
(07-09-2019, 03: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.
Reply

#6
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.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.