Welcome Guest, Not a member yet? Register   Sign In
<p>Message: Cannot use object of type stdClass as array</p>
#5

Your using twig templates so not really sure how twig is doing it but the foreach is nothing like CodeIgniters.

you can use this helper to see what your object is looking like, if it's a CodeIgniter database returned object
then it will be an object in an object.

PHP Code:
<?php

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

/**
 * varDebug () - Add this method to a CodeIgniter Helper.
 * I named mine - debug_helper.php
 * -----------------------------------------------------------------------
 *
 * Formatted output of var_dump() etc;
 */
if ( ! function_exists('varDebug'))
{
    
/**
     * Debug Helper
     * -------------------------------------------------------------------
     * Outputs the given variable(s) with color formatting and location
     *
     * @param    mixed    - variables to be output
     */
    
function varDebug()
    {
        list(
$callee) = debug_backtrace();

        
$arguments func_get_args();

        
$total_arguments func_num_args();

        echo 
'<div><fieldset style="background: #fefefe !important; border:1px red solid; padding:15px">';
        echo 
'<legend style="background:lightgrey; padding:5px;">'.$callee['file'].' @line: '.
        
     $callee['line'].'</legend><pre><code>';

        
$i 0;
        foreach (
$arguments as $argument) {
            echo 
'<strong>Debug #'.++$i.' of '.$total_arguments.'</strong>: '.'<br>';
            
var_dump($argument);
        }

        echo 
"</code></pre></fieldset><div><br>";

        exit;
    }
}

/**
 * -----------------------------------------------------------------------
 * Filename: debug_helper.php
 * Location: ./app/Helpers/debug_helper.php
 * -----------------------------------------------------------------------
 */ 

Pass in your object that is giving you an error and this will give you a formatted output of it.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Messages In This Thread
RE: <p>Message: Cannot use object of type stdClass as array</p> - by InsiteFX - 11-24-2020, 02:21 AM



Theme © iAndrew 2016 - Forum software by © MyBB