Welcome Guest, Not a member yet? Register   Sign In
getting non-object error only in log file
#2

(This post was last modified: 09-10-2017, 11:43 AM by InsiteFX. Edit Reason: spelling error )

Your $data is an associate array and your trying to assign an object to it.

PHP Code:
if ( ! function_exists('arrayToObject'))
{
    
/**
     * arrayToObject ()
     * -------------------------------------------------------------------
     *
     * Converts an array to an object.
     *
     * USAGE: $obj = arrayToObject($data)
     *
     * @param   $data
     * @return  object
     */
    
function arrayToObject($data)
    {
        if (
is_array($data))
        {
            
/**
             * Return array converted to object Using __FUNCTION__
             * (Magic constant) for recursive calls
             */
            
return (object) array_map(__FUNCTION__$data);
        }
        else
        {
            return 
$data;
        }
    }
}

if ( ! 
function_exists('objectToArray'))
{
    
/**
     * objectToArray ()
     * -------------------------------------------------------------------
     *
     * Converts an object to an array.
     *
     * USAGE: $array = objectToArray($object);
     *
     * @param  $obj
     * @return array
     */
    
function objectToArray($obj)
    {
        if (
is_object($obj))
        {
            
// Gets the properties of the given object with get_object_vars function
            
$obj get_object_vars($obj);
        }

        if (
is_array($obj))
        {
            
/**
             * Return array converted to object Using __FUNCTION__
             * (Magic constant) for recursive calls
             */
            
return array_map(__FUNCTION__$obj);
        }
        else
        {
            return 
$obj;
        }
    }


Place these two methods / Functions in a CodeIgniter Helper.

Usage:

PHP Code:
$data['theForm'] = objectToArray($this->form->get_one_by(array('URL' => $url))); 

See if that will fix your problem.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Messages In This Thread
RE: getting non-object error only in log file - by InsiteFX - 09-10-2017, 11:42 AM



Theme © iAndrew 2016 - Forum software by © MyBB