Welcome Guest, Not a member yet? Register   Sign In
going from json_decode to insert_batch
#4

(This post was last modified: 04-16-2018, 10:14 AM by InsiteFX.)

Just create your own helper under ./application/helpers

EXAMPLE: uitlity_helper.php

Add all of the above into that file.

To use:

PHP Code:
$array  objectToArray($your_object_data);

$object arrayToObject($your_array_data);

varDebug($array or $object);
exit(); 

Hope that helps.

Place this in ./application/helpers/utility_helper.php

PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

/**
 * -----------------------------------------------------------------------
 * Editor   : PhpStorm
 * Date     : 4/16/2018
 * Time     : 1:07 PM
 * Authors  : Raymond L King Sr.
 * -----------------------------------------------------------------------
 *
 * Class        Name
 *
 * @project     ci3blog
 * @author      Raymond L King Sr.
 * @link        http://www.procoversfx.com
 * @copyright   Copyright (c) 2009 - 2018 Custom Software Designers, LLC.
 * @license     http://www.procoversfx.com/license
 * -----------------------------------------------------------------------
 */

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

/**
 * objectToArray ()
 *
 * Usage:
 *
 * $array = objectToArray($your_object_data)
 */
if ( ! function_exists('objectToArray'))
{
    
/**
     * objectToArray ()
     * -------------------------------------------------------------------
     *
     * @param  $data
     * @return array
     */
    
function objectToArray($data)
    {
        if (
is_object($data))
        {
            
/**
             * Gets the properties of the given object
             * with get_object_vars function
             */
            
$data get_object_vars($data);
        }

        
/**
         * Return array converted to object Using __FUNCTION__ (Magic constant)
         * for recursive call
         */
        
return (is_array($data))
            ? 
array_map(__FUNCTION__$data)
            : 
$data;
    }
}

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

/**
 * arrayToObject ()
 *
 * Usage:
 *
 * $object = arrayToObject($your_array_data);
 */
if ( ! function_exists('arrayToObject'))
{
    
/**
     * arrayToObject ()
     * -------------------------------------------------------------------
     *
     * @param  $data
     * @return object
     */
    
function arrayToObject($data)
    {
        
/**
         * Return array converted to object Using __FUNCTION__ (Magic constant)
         * for recursive call
         */
        
return (is_array($data))
            ? (object) 
array_map(__FUNCTION__$data)
            : 
$data;
    }
}

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

/**
 * varDebug () - Add this method to a CodeIgniter Helper.
 * -----------------------------------------------------------------------
 *
 * Formatted output of var_dump() or print_r() see comment below etc;
 *
 * Usage:
 *
 * varDebug($array or $object);
 * exit();
 *
 */
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>';

            
// You can also change this to print_r() if needed.
            
var_dump($argument);
        }

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

/**
 * -----------------------------------------------------------------------
 * Filename: utility_helper.php
 * Location: ./application/helpers/utility_helper.php
 * -----------------------------------------------------------------------
 */ 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Messages In This Thread
RE: going from json_decode to insert_batch - by InsiteFX - 04-16-2018, 09:55 AM



Theme © iAndrew 2016 - Forum software by © MyBB