CodeIgniter Forums
how to inspect the data array in the view. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: how to inspect the data array in the view. (/thread-10369.html)

Pages: 1 2


how to inspect the data array in the view. - El Forum - 07-29-2008

[eluser]scaryjack[/eluser]
hi,
is there any way to see ALL data an item contains in the view?

to make it more clear:
in the controller I load the view and give in the second parameter an data array.

So how can I inspect the data array( e.g. that it shows all identifiers)? In CakePHP you could easliy print everything with one function call.


how to inspect the data array in the view. - El Forum - 07-29-2008

[eluser]Michael Wales[/eluser]
Code:
var_dump($data); // Or whatever your array is named



how to inspect the data array in the view. - El Forum - 07-29-2008

[eluser]elvix[/eluser]
I always create a helper function that takes an array and prints it out surrounded by pre tags for easier reading. You could use var_dump() in there as well.

in custom_helper.php:

Code:
function print_rr($arr) {
    echo "<pre>";
    print_r($arr);
    echo "</pre>";
}



how to inspect the data array in the view. - El Forum - 07-30-2008

[eluser]scaryjack[/eluser]
the helper is a good idea.

but one thing remains unclear...
if I have this:
this->load->view("view", $data);

how can I print $data in the view? Because I access the values in the view directly, never call the $data var.
Or is this possible and I missed all the time to try it?


how to inspect the data array in the view. - El Forum - 07-30-2008

[eluser]myerman[/eluser]
do a var_dump() or print_r() from your controller function....that will dump it out onto your view....


how to inspect the data array in the view. - El Forum - 07-30-2008

[eluser]scaryjack[/eluser]
ok, thx alot!


how to inspect the data array in the view. - El Forum - 07-30-2008

[eluser]Colin Williams[/eluser]
Better solution if there is HTML code in your $data array:

Code:
function print_rr($arr, $store = FALSE)
{
   $output = '<pre>'. htmlspecialchars(print_r($arr, TRUE)) .'</pre>';
   if ($store === TRUE)
   {
      return $output;
   }
   else
   {
      print $output;
   }
}



how to inspect the data array in the view. - El Forum - 07-30-2008

[eluser]Bramme[/eluser]
You could use the xmp tag instead off pre, so you wouldn't have to use the htmlspecialchars function, but on the other hand, it's deprecated... So we shouldn't be using it at all...


how to inspect the data array in the view. - El Forum - 07-30-2008

[eluser]khmer angkor[/eluser]
Code:
function updateProfile($userID) {
        $data = array(
                    'password' => $this->password,
                    'fullname' => $this->fullname,
                    'phone' => $this->phone,
                    'email' => $this->email
                    );
        $this->db->where('userID', $userID);
        $status = $this->db->update('sys_user', $data);

        return $status;



how to inspect the data array in the view. - El Forum - 07-30-2008

[eluser]Bramme[/eluser]
[quote author="khmer angkor" date="1217421645"]
Code:
function updateProfile($userID) {
        $data = array(
                    'password' => $this->password,
                    'fullname' => $this->fullname,
                    'phone' => $this->phone,
                    'email' => $this->email
                    );
        $this->db->where('userID', $userID);
        $status = $this->db->update('sys_user', $data);

        return $status;
[/quote]
And that has what to do with this topic?