Cannot use object of type stdClass as array - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Cannot use object of type stdClass as array (/showthread.php?tid=65519) |
Cannot use object of type stdClass as array - davy_yg - 06-21-2016 Hello, I am having prob. with this new error. Can anyone help me fix the error? PAGES NAME CREATE DATE ORDER EDIT VIEW CONTENT DELETE Fatal error: Cannot use object of type stdClass as array in C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyProfileCI\application\views\pages.php on line 58 A PHP Error was encountered Severity: Error Message: Cannot use object of type stdClass as array Filename: views/pages.php Line Number: 58 Backtrace: views/pages.php PHP Code: <?php foreach ($pages as $pages_item): ?> Line 58 is : PHP Code: <td><?php echo $pages_item['pages_name']; ?></td> I do not know how to fix the error - can any one help me fix the error? Thanks in advance, Davy RE: Cannot use object of type stdClass as array - JayAdra - 06-21-2016 $pages_item is an object, not an array. Try accessing data like this instead: PHP Code: <td><?php echo $pages_item->pages_name; ?></td> RE: Cannot use object of type stdClass as array - davy_yg - 06-22-2016 A little bit better but I still have prob. here: ------------------------------------------------ A PHP Error was encountered Severity: Notice Message: Undefined property: stdClass::$order Filename: views/pages.php Line Number: 60 --------------------------------------------- Line 60: <td><?php echo $pages_item->order; ?></td> Can you help? RE: Cannot use object of type stdClass as array - JayAdra - 06-22-2016 You really need to learn basic PHP and debugging skills. These are simple errors. "Undefined property" means that your object doesn't have an "order" property. I'm guessing your $pages_item is being returned from your database, so you either don't have have an "order" column, or you're not setting it when you're creating the $pages_item object. |