简体   繁体   中英

A PHP Error was encountered Severity: Warning Message: Undefined property: stdClass:: $cancelled

I got this error message when running PHP Code Igniter project:

A PHP Error was encountered Severity: Warning Message: Undefined property: stdClass::$cancelled Filename: transactions/transtable.php Line Number: 38

Backtrace:

File: C:\xampp\htdocs\mini-inventory-and-sales-management-system\application\views\transactions\transtable.php Line: 38 Function: _error_handler

File: C:\xampp\htdocs\mini-inventory-and-sales-management-system\application\controllers\Search.php Line: 103 Function: view

File: C:\xampp\htdocs\mini-inventory-and-sales-management-system\index.php Line: 315 Function: require_once

Here is transactions/transtable.php Line Number: 38

<td><?=$get->cancelled ? 'cancelled' : 'Completed'?></td>

If you are trying to bring something from the database with the model from the controller, you should look that the name of the variable that you bring before assign to the response of the controller (in the controller), need to be named exactly the same as the column name in database. fe:

if($query = $this->some_model->getModels(){
     foreach($query->result() as $res){
        $row = new stdClass();
        $row->first_data = $res->THE_SAME_AS_IN_DB; (it's case sensitive too)
     }
}

And in the model i usually use raw queries, but if youre using the CI functions, its the same name as the column in db.

Maybe if you post more info about the error, i can be more exactly, but some of the most typical reason of that error is because the variable is empty, and you try to use it .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM