Welcome Guest, Not a member yet? Register   Sign In
How do you print all config vars to screen?
#1

[eluser]codex[/eluser]
I accidentally did it a few times, but I can't remember what it was. Something like print_r($config) (but that's obviously isn't working).

Also, is it possible to add config vars to the array without placing them in config files?
edit: yes, with $this->config->set_item('item_name', 'item_value');
#2

[eluser]wiredesignz[/eluser]
Use Modular Extensions debug helper : debug($this->config) or debug_in($this->config)
#3

[eluser]Pascal Kriete[/eluser]
You can get all the currently loaded config vars with:
Code:
print_r($this->config);

Edit: wired was too quick Smile .
#4

[eluser]codex[/eluser]
[quote author="inparo" date="1209962753"]You can get all the currently loaded config vars with:
Code:
print_r($this->config);

Edit: wired was too quick Smile .[/quote]

That was what I was thinking, but I use a function 'p()' (I believe Lone made it) that prints out print_r(), but in a nicer layout. But just not $this->config :-)

Thanks!
#5

[eluser]codex[/eluser]
[quote author="wiredesignz" date="1209962713"]Use Modular Extensions debug helper : debug($this->config) or debug_in($this->config)[/quote]

Wire(d) to the rescue! ;-)
#6

[eluser]John_Betong[/eluser]
 
Try this formatted output which I find is far more readable:
 
Code:
echo '<pre>';
     print_r($this->config);
  echo '</pre>';
&nbsp;
&nbsp;
#7

[eluser]spheroid[/eluser]
Here's the p() function. I put in MY_Controller:

Code:
function p($var)
    {
        if(is_array($var))
        {
            $array = 1;
            $title = 'Array Output';
        }
        else
        {
            $array = 0;
            $title = 'Variable Output';
        }
    
        echo '<div style="background:#eee; border:1px solid #888; color: #444; font-size: 12px; clear:both;">'."\n";
        echo '<h5 style="font-weight:bold; font-size:1.2em; line-height: 1.4em;">'.$title.'</h5>'."\n";
        
        if($array) {
            echo '<pre>'."\n";
            print_r($var);
            echo '</pre>'."\n";
        }
        else
        {
            echo $var;
        }
        
        echo '</div>'."\n";
    }
#8

[eluser]wiredesignz[/eluser]
And here is Modular Extensions debug_helper.php for those that are interested.
Code:
&lt;?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* Modular Extensions - HMVC
*
* Debug Helper
*
* Version 4.0.29 (c) Wiredesignz 2008-04-28
*/

/**
* Debug
*
* Lists object_vars for an object
**/
function debug($_this)
{
    if (is_object($_this))
    {
        echo '<pre>',get_class($_this),' Object: '."\n",
        print_r(array_keys(get_object_vars($_this)), TRUE),'</pre>';
        echo '<br />';
    }
}

/**
* Debug_in
*
* Dumps contents of an object or array
**/
function debug_in($_this)
{
    if (is_object($_this))
    {
        echo '<pre>',get_class($_this),' Object: '."\n",
        print_r(get_object_vars($_this), TRUE),'</pre>';
        echo '<br />';
    }
    
    if (is_array($_this))
    {
        echo '<pre>',
        print_r($_this, TRUE),'</pre>';
        echo '<br />';
    }
}
#9

[eluser]louis w[/eluser]
Just to throw in my 2 cents. Here is the function I use for displaying array contents.

I wanted to be able to pass in a title to label the display. Also by using true as the second param in print_r it will be treated as a string. Then I can do things such as email it or display it in the debug logs.


Code:
function print_r_pre($array,$title=false,$echo=true) {
    
    if (!is_array($array)) return;
    
    $output = '<pre>'
            . ((!empty($title)) ? '<strong>'.$title.' =</strong> ' : '')
            . print_r($array, true)
            . '</pre>';

    if ($echo) {
        echo $output;
    } else {
        return $output;
    }
    
}




Theme © iAndrew 2016 - Forum software by © MyBB