CodeIgniter Forums
Call to undefined method App\Models\[...]::transStart - 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: Call to undefined method App\Models\[...]::transStart (/showthread.php?tid=78061)



Call to undefined method App\Models\[...]::transStart - webdevron - 11-25-2020

My model function is given bellow:

PHP Code:
class Product extends Model
{

    protected $table            'products';
    protected $primaryKey      'product_ID';
    protected $returnType      'object';
    protected $useSoftDeletes  false;
    protected $allowedFields    = ['....'];


    public function saveProduct$new ){
        $val = [];
        if( $new ){
            $val['product_AID']    AID;
            $val['product_GPID']    $this->GPID();
            $val['product_by']      session('user41BApp'.AID);
        }else{
            $info['updated']        time();
        }

        $val['product_title']  esc($this->request->getPost('pName'));
        $val['product_slug']    planeText(esc($this->request->getPost('pName')));
        $val['product_price']  esc($this->request->getPost('pPrice'));
        $val['product_data']    json_encode($data);
        $val['product_info']    json_encode($info);

        $this->transStart();
        $this->save($val);
        $this->saveCat();
        $this->transComplete();

        return ($this->transStatus() === FALSE) ? FALSE : [$val['product_GPID'], $this->request->getPost('cat')];

    }




There is a strange problem.
PHP Code:
model->saveProduct(true); // This is working fine 

PHP Code:
model->saveProduct(false); // This is not working. Showing error:
//Call to undefined method App\Models\Product::transStart 



RE: Call to undefined method App\Models\[...]::transStart - neoneeco - 11-25-2020

1) Have you tested without this method? (commenting it)

2) It may seem obvious, is this method well implemented ? the code doesn't show it, with the closing class brace.


RE: Call to undefined method App\Models\[...]::transStart - InsiteFX - 11-25-2020

PHP Code:
$this->db->transStart();
$this->save($val);
$this->saveCat();
$this->db->transComplete(); 



RE: Call to undefined method App\Models\[...]::transStart - webdevron - 11-29-2020

(11-25-2020, 06:22 AM)neoneeco Wrote: 1) Have you tested without this method? (commenting it)

2) It may seem obvious, is this method well implemented? the code doesn't show it, with the closing class brace.

Thank you for your response.
1. Without transection, both method are doing as expected.
Code:
model->saveProduct(true); // Saving product
model->saveProduct(false); // Updating product

With transection only the update product "model->saveProduct(false);" showing the error.

2. This method is a part of a large class. Everything is doing well except the update method.

(11-25-2020, 03:43 PM)InsiteFX Wrote:
PHP Code:
$this->db->transStart();
$this->save($val);
$this->saveCat();
$this->db->transComplete(); 

I am not using Query Builder. Using inherited Codeigniter model instead. Again those method are not working just for
PHP Code:
model->saveProduct(false); 



RE: Call to undefined method App\Models\[...]::transStart - ojmichael - 11-29-2020

PHP Code:
$info['updated']        time(); 

Why is this line using the variable $info and not $val (like the rest) ?


RE: Call to undefined method App\Models\[...]::transStart - webdevron - 11-30-2020

(11-29-2020, 11:34 PM)ojmichael Wrote:
PHP Code:
$info['updated']        time(); 

Why is this line using the variable $info and not $val (like the rest) ?

This is using in the last line where assigning the value:
PHP Code:
$val['product_info']    = json_encode($info); 



RE: Call to undefined method App\Models\[...]::transStart - InsiteFX - 11-30-2020

I would check the model code, because an update requires that an id field be passed to it.